Java Code Examples for java.io.ObjectOutputStream#flush()

The following examples show how to use java.io.ObjectOutputStream#flush() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk8u-jdk   File: Floats.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int nbatches, int ncycles)
    throws Exception
{
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeFloat((float) 0.0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readFloat();
        }
    }
}
 
Example 2
/**
 * Run benchmark for given number of batches, with each batch containing
 * the given number of cycles.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, Node[] trees, int nbatches)
    throws Exception
{
    int ncycles = trees.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(trees[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
 
Example 3
/**
 * Run benchmark for given number of batches, with each batch containing the
 * given number of cycles.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, Node[] trees, int nbatches)
    throws Exception
{
    int ncycles = trees.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(trees[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
 
Example 4
Source Project: jdk8u-dev-jdk   File: Ints.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int nbatches, int ncycles)
    throws Exception
{
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeInt(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readInt();
        }
    }
}
 
Example 5
@Test
public void testSerializeBytes() throws Exception {
    byte[] testBytes = SerializationUtils.serialize(iMap);

    ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(streamReal);
    oos.writeObject(iMap);
    oos.flush();
    oos.close();

    byte[] realBytes = streamReal.toByteArray();
    assertEquals(testBytes.length, realBytes.length);
    for (int i = 0; i < realBytes.length; i++) {
        assertEquals(realBytes[i], testBytes[i]);
    }
}
 
Example 6
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int nbatches, int ncycles)
    throws Exception
{
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeBoolean(false);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readBoolean();
        }
    }
}
 
Example 7
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, char[][] arrays, int nbatches)
    throws Exception
{
    int ncycles = arrays.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(arrays[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
 
Example 8
static void testSerialization() throws Exception {
    Currency currency1 = Currency.getInstance("DEM");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oStream = new ObjectOutputStream(baos);
    oStream.writeObject(currency1);
    oStream.flush();
    byte[] bytes = baos.toByteArray();

    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream iStream = new ObjectInputStream(bais);
    Currency currency2 = (Currency) iStream.readObject();

    if (currency1 != currency2) {
        throw new RuntimeException("serialization breaks class invariant");
    }
}
 
Example 9
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, char[][] arrays, int nbatches)
    throws Exception
{
    int ncycles = arrays.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(arrays[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
 
Example 10
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int nbatches, int ncycles)
    throws Exception
{
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeChar('0');
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readChar();
        }
    }
}
 
Example 11
protected byte[] serialize(ActiveMQMessageAuditNoSync audit) throws Exception {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   ObjectOutputStream oout = new ObjectOutputStream(baos);
   oout.writeObject(audit);
   oout.flush();
   return baos.toByteArray();
}
 
Example 12
private void writeCounter()
{
    try {
        counterFile.delete();
        FileOutputStream fos = new FileOutputStream(counterFile);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(counter);
        oos.flush();
        oos.close();

    } catch (Exception ex) {
    }
}
 
Example 13
/**
 * Run benchmark for given number of cycles.
 */
void doReps(StreamBuffer sbuf, Dummy dummy, int reps) throws Exception {
    OutputStream out = sbuf.getOutputStream();
    InputStream in = sbuf.getInputStream();
    for (int i = 0; i < reps; i++) {
        sbuf.reset();
        ObjectOutputStream oout = new ObjectOutputStream(out);
        oout.writeObject(dummy);
        oout.flush();
        ObjectInputStream oin = new ObjectInputStream(in);
        oin.readObject();
    }
}
 
Example 14
public void save(String fileName) {
	// for now I serialize the combo model from a file
	try {
		FileOutputStream fileStream = new FileOutputStream(fileName);
		ObjectOutputStream objectStream = new ObjectOutputStream(fileStream);
		objectStream.writeObject(getModel());
		objectStream.flush();
		objectStream.close();
		fileStream.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 15
Source Project: moa   File: SerializeUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void writeToFile(File file, Serializable obj)
        throws IOException {
    ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(
            new BufferedOutputStream(new FileOutputStream(file))));
    out.writeObject(obj);
    out.flush();
    out.close();
}
 
Example 16
@Override
public void write(Kryo kryo, Output output, Object object) {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  try {
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(object);
    oos.flush();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  byte[] ser = bos.toByteArray();
  output.writeInt(ser.length);
  output.writeBytes(ser);
}
 
Example 17
public void writeWire(final DataOutputStream out) throws IOException {

      super.writeWire(out);
      final ObjectOutputStream oos = new ObjectOutputStream(out);
      try {
         oos.writeObject(executable);
         oos.flush();
      } finally {
         IOUtils.closeHard(oos);
      }
   }
 
Example 18
/**
 * Run benchmark for given number of cycles.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, ObjectStreamClass desc, int ncycles)
    throws Exception
{
    for (int i = 0; i < ncycles; i++) {
        sbuf.reset();
        oout.reset();
        oout.writeObject(desc);
        oout.flush();
        oin.readObject();
    }
}
 
Example 19
@Override
public void serialize(@NonNull DataOutput2 out, @NonNull SessionTypeWorkerId value) throws IOException {
    ObjectOutputStream out2 = new ObjectOutputStream(out);
    out2.writeObject(value);
    out2.flush();
}
 
Example 20
Source Project: beam   File: SerializableCoder.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void encode(T value, OutputStream outStream) throws IOException {
  ObjectOutputStream oos = new ObjectOutputStream(outStream);
  oos.writeObject(value);
  oos.flush();
}