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

The following examples show how to use java.io.ObjectOutputStream#flush() . 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 File: Booleans.java    From openjdk-jdk8u-backup with 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.writeBoolean(false);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readBoolean();
        }
    }
}
 
Example 2
Source File: Chars.java    From openjdk-8-source with 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.writeChar('0');
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readChar();
        }
    }
}
 
Example 3
Source File: CharArrays.java    From jdk8u-jdk with 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, 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 4
Source File: CurrencyTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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 5
Source File: CharArrays.java    From openjdk-jdk8u with 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, 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 6
Source File: Floats.java    From jdk8u-jdk with 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 7
Source File: SerializationUtilsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@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 8
Source File: Ints.java    From jdk8u-dev-jdk with 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 9
Source File: SmallObjTrees.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 10
Source File: CustomDefaultObjTrees.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 11
Source File: Cons.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 12
Source File: HistoryComboBox.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
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 13
Source File: SerializeUtils.java    From moa with 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 14
Source File: ServantManagerImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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 15
Source File: SerializableSerializer.java    From incubator-heron with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: ActiveMQMessageAuditTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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 17
Source File: ExecuteAllRequest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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
Source File: ClassDesc.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Source File: MapDBStatsStorage.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@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 File: SerializableCoder.java    From beam with 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();
}