Java Code Examples for java.io.ObjectOutputStream

The following examples show how to use java.io.ObjectOutputStream. These examples are extracted from open source projects.
Example 1
Project: dragonwell8_jdk   File: ObjArrays.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, Node[][] 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 2
Project: openjdk-jdk9   File: ModelMBeanInfoSupport.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serializes a {@link ModelMBeanInfoSupport} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
throws IOException {
    if (compat) {
        // Serializes this instance in the old serial form
        //
        ObjectOutputStream.PutField fields = out.putFields();
        fields.put("modelMBeanDescriptor", modelMBeanDescriptor);
        fields.put("mmbAttributes", modelMBeanAttributes);
        fields.put("mmbConstructors", modelMBeanConstructors);
        fields.put("mmbNotifications", modelMBeanNotifications);
        fields.put("mmbOperations", modelMBeanOperations);
        fields.put("currClass", currClass);
        out.writeFields();
    } else {
        // Serializes this instance in the new serial form
        //
        out.defaultWriteObject();
    }
}
 
Example 3
Project: openjdk-8   File: NumericValueExp.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serializes a {@link NumericValueExp} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("doubleVal", doubleValue());
    fields.put("longVal", longValue());
    fields.put("valIsLong", isLong());
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 4
Project: frog   File: EggTool.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Frogs which have higher energy lay eggs
 * 
 * 利用Java串行机制存盘。 能量多(也就是吃的更多)的Frog下蛋并存盘, 以进行下一轮测试,能量少的Frog被淘汰,没有下蛋的资格。
 * 用能量的多少来简化生存竟争模拟,每次下蛋数量固定为EGG_QTY个
 */
public static void layEggs() {
	sortFrogsOrderByEnergyDesc();

	Frog first = Env.frogs.get(0);
	Frog last = Env.frogs.get(Env.frogs.size() - 1);

	try {
		Env.eggs.clear();
		for (int i = 0; i < Env.EGG_QTY; i++)
			Env.eggs.add(new Egg(Env.frogs.get(i)));
		FileOutputStream fo = new FileOutputStream(Application.CLASSPATH + "eggs.ser");
		ObjectOutputStream so = new ObjectOutputStream(fo);
		so.writeObject(Env.eggs);
		so.close();
		System.out.print("\r1st frog has " + first.organs.size() + " organs, energy=" + first.energy  );
		System.out.println(", Last frog has " + last.organs.size() + " organs,  energy=" + last.energy);
		System.out.println("Saved "+Env.eggs.size() +" eggs to file '" + Application.CLASSPATH + "eggs.ser'");
	} catch (IOException e) {
		System.out.println(e);
	}
}
 
Example 5
Project: openjdk-jdk9   File: ModelMBeanOperationInfo.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serializes a {@link ModelMBeanOperationInfo} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("operationDescriptor", operationDescriptor);
    fields.put("currClass", currClass);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 6
Project: Flink-CEPplus   File: MemoryCheckpointStorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskOwnedStateStream() throws Exception {
	final List<String> state = Arrays.asList("Flopsy", "Mopsy", "Cotton Tail", "Peter");

	final MemoryBackendCheckpointStorage storage = new MemoryBackendCheckpointStorage(
			new JobID(), null, null, DEFAULT_MAX_STATE_SIZE);

	StreamStateHandle stateHandle;

	try (CheckpointStateOutputStream stream = storage.createTaskOwnedStateStream()) {
		assertTrue(stream instanceof MemoryCheckpointOutputStream);

		new ObjectOutputStream(stream).writeObject(state);
		stateHandle = stream.closeAndGetHandle();
	}

	try (ObjectInputStream in = new ObjectInputStream(stateHandle.openInputStream())) {
		assertEquals(state, in.readObject());
	}
}
 
Example 7
Project: netbeans   File: EventBufferDumpedCommand.java    License: Apache License 2.0 6 votes vote down vote up
void writeObject(ObjectOutputStream out) throws IOException {
    out.writeInt(bufSize);
    out.writeBoolean(buffer != null);
    if (buffer != null) {
        Deflater compressor = new Deflater();
        // for small buffers, the compressed size can be somewhat larger than the original  
        byte[] compressedBytes = new byte[bufSize + 32]; 
        int compressedSize;
        
        compressor.setInput(buffer,startPos,bufSize);
        compressor.finish();
        compressedSize = compressor.deflate(compressedBytes);
        out.writeInt(compressedSize);
        out.write(compressedBytes,0,compressedSize);
    } else {
        out.writeUTF(eventBufferFileName);
    }
}
 
Example 8
Project: j2objc   File: DateFormatSymbolsTest.java    License: Apache License 2.0 6 votes vote down vote up
public void test_serialization() throws Exception {
    DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRANCE);
    String[][] zoneStrings = symbols.getZoneStrings();
    assertNotNull(zoneStrings);

    // serialize
    ByteArrayOutputStream byteOStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOStream = new ObjectOutputStream(byteOStream);
    objectOStream.writeObject(symbols);

    // and deserialize
    ObjectInputStream objectIStream = new ObjectInputStream(
            new ByteArrayInputStream(byteOStream.toByteArray()));
    DateFormatSymbols symbolsD = (DateFormatSymbols) objectIStream
            .readObject();

    String[][] zoneStringsD = symbolsD.getZoneStrings();
    assertNotNull(zoneStringsD);
    assertEquals(symbols, symbolsD);
}
 
Example 9
Project: dragonwell8_jdk   File: Permissions.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Default fields.
 */
/*
 * Writes the contents of the permsMap field out as a Hashtable for
 * serialization compatibility with earlier releases.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Don't call out.defaultWriteObject()

    // Copy perms into a Hashtable
    Hashtable<Permission, Permission> perms =
            new Hashtable<>(permsMap.size()*2);
    synchronized (this) {
        perms.putAll(permsMap);
    }

    // Write out serializable fields
    ObjectOutputStream.PutField pfields = out.putFields();
    pfields.put("perms", perms);
    out.writeFields();
}
 
Example 10
Project: openjdk-jdk8u-backup   File: ClassDesc.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write and read class descriptors to/from a stream.
 * Arguments: <# cycles>
 */
public long run(String[] args) throws Exception {
    int ncycles = Integer.parseInt(args[0]);
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());
    ObjectStreamClass desc = ObjectStreamClass.lookup(Dummy50.class);

    doReps(oout, oin, sbuf, desc, 1);       // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, desc, ncycles);
    return System.currentTimeMillis() - start;
}
 
Example 11
Project: datawave   File: EdgeQueryLogic.java    License: Apache License 2.0 6 votes vote down vote up
protected String serializePrefilter() {
    
    String retVal = null;
    if (prefilterValues != null) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(prefilterValues);
            oos.close();
        } catch (IOException ex) {
            log.error("Some error encoding the prefilters...", ex);
        }
        retVal = new String(Base64.encodeBase64(baos.toByteArray()));
    }
    
    return retVal;
}
 
Example 12
Project: openjdk-8-source   File: FloatArrays.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, float[][] 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 13
Project: ThriftBook   File: FileTrans.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) 
        throws IOException, TTransportException, ClassNotFoundException {
    Trade trade = new Trade();
    trade.symbol = "F";
    trade.price = 13.10;
    trade.size = 2500;

    TSimpleFileTransport trans_out = new TSimpleFileTransport("data",false,true);	
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(trade);
    trans_out.write(baos.toByteArray());				
    trans_out.close();				

    TSimpleFileTransport trans_in = new TSimpleFileTransport("data",true,false);
    byte[] buf = new byte[128];
    int iBytesRead = trans_in.read(buf, 0, buf.length);		
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);
    ObjectInputStream ois = new ObjectInputStream(bais);
    trade = (Trade) ois.readObject();

    System.out.println("Trade(" + iBytesRead + "): " + trade.symbol
            + " " + trade.size + " @ " + trade.price);
}
 
Example 14
Project: astor   File: StackedXYAreaRendererTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    StackedXYAreaRenderer r1 = new StackedXYAreaRenderer();
    r1.setShapePaint(Color.red);
    r1.setShapeStroke(new BasicStroke(1.23f));
    StackedXYAreaRenderer r2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(r1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        r2 = (StackedXYAreaRenderer) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(r1, r2);
}
 
Example 15
Project: astor   File: StrokeMapTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for serialization.
 */
public void testSerialization2() {
    StrokeMap m1 = new StrokeMap();
    m1.put("K1", new BasicStroke(1.1f));
    m1.put("K2", new BasicStroke(2.2f));
    StrokeMap m2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(m1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(
                buffer.toByteArray()));
        m2 = (StrokeMap) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(m1, m2);
}
 
Example 16
Project: astor   File: MeanAndStandardDeviationTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    MeanAndStandardDeviation m1 = new MeanAndStandardDeviation(1.2, 3.4);
    MeanAndStandardDeviation m2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(m1);
        out.close();

        ObjectInput in = new ObjectInputStream(
            new ByteArrayInputStream(buffer.toByteArray())
        );
        m2 = (MeanAndStandardDeviation) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(m1, m2);

}
 
Example 17
Project: hottub   File: DocumentImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example 18
Project: openjdk-jdk8u   File: SmallObjTrees.java    License: 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 19
Project: ratis   File: ArithmeticStateMachine.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public long takeSnapshot() {
  final Map<String, Double> copy;
  final TermIndex last;
  try(final AutoCloseableLock readLock = readLock()) {
    copy = new HashMap<>(variables);
    last = getLastAppliedTermIndex();
  }

  final File snapshotFile =  storage.getSnapshotFile(last.getTerm(), last.getIndex());
  LOG.info("Taking a snapshot to file {}", snapshotFile);

  try(final ObjectOutputStream out = new ObjectOutputStream(
      new BufferedOutputStream(new FileOutputStream(snapshotFile)))) {
    out.writeObject(copy);
  } catch(IOException ioe) {
    LOG.warn("Failed to write snapshot file \"" + snapshotFile
        + "\", last applied index=" + last);
  }

  return last.getIndex();
}
 
Example 20
Project: openjdk-8   File: Ints.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write and read int values to/from a stream.  The benchmark is run in
 * batches: each "batch" consists of a fixed number of read/write cycles,
 * and the stream is flushed (and underlying stream buffer cleared) in
 * between each batch.
 * Arguments: <# batches> <# cycles per batch>
 */
public long run(String[] args) throws Exception {
    int nbatches = Integer.parseInt(args[0]);
    int ncycles = Integer.parseInt(args[1]);
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());

    doReps(oout, oin, sbuf, 1, ncycles);    // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, nbatches, ncycles);
    return System.currentTimeMillis() - start;
}
 
Example 21
Project: jdk8u_jdk   File: ShortArrays.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write and read short arrays to/from a stream.  The benchmark is run in
 * batches, with each batch consisting of a fixed number of read/write
 * cycles.  The ObjectOutputStream is reset after each batch of cycles has
 * completed.
 * Arguments: <array size> <# batches> <# cycles per batch>
 */
public long run(String[] args) throws Exception {
    int size = Integer.parseInt(args[0]);
    int nbatches = Integer.parseInt(args[1]);
    int ncycles = Integer.parseInt(args[2]);
    short[][] arrays = new short[ncycles][size];
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());

    doReps(oout, oin, sbuf, arrays, 1);     // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, arrays, nbatches);
    return System.currentTimeMillis() - start;
}
 
Example 22
Project: openjdk-8-source   File: SerializationTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void test(Object a) {
    try {
        File objectbin = new File("object.bin");
        FileOutputStream fos = new FileOutputStream(objectbin);
        ObjectOutputStream out = new ObjectOutputStream(fos);
        out.writeObject(a);
        fos.close();
        FileInputStream fis = new FileInputStream(objectbin);
        ObjectInputStream in = new ObjectInputStream(fis);
        Object o = in.readObject();
        fis.close();
        System.err.println(o);
    } catch (Throwable ex) {
        ex.printStackTrace();
        failed = true;
    }
}
 
Example 23
Project: joshua   File: BloomFilterLanguageModel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Builds a language model and stores it in a file.
 * 
 * @param argv command-line arguments
 */
public static void main(String[] argv) {
  if (argv.length < 5) {
    String msg = "usage: BloomFilterLanguageModel <statistics file> <order> <size>"
        + " <quantization base> <output file>";
    System.err.println(msg);
    LOG.error(msg);
    return;
  }
  int order = Integer.parseInt(argv[1]);
  int size = (int) (Integer.parseInt(argv[2]) * Math.pow(2, 23));
  double base = Double.parseDouble(argv[3]);

  try {
    BloomFilterLanguageModel lm = new BloomFilterLanguageModel(argv[0], order, size, base);

    ObjectOutputStream out =
        new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(argv[4])));

    lm.writeExternal(out);
    out.close(); //TODO: try-with-resources
  } catch (IOException e) {
    LOG.error(e.getMessage(), e);
  }
}
 
Example 24
Project: astor   File: XYCoordinateTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    XYCoordinate v1 = new XYCoordinate(1.0, 2.0);
    XYCoordinate v2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(v1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        v2 = (XYCoordinate) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(v1, v2);
}
 
Example 25
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    SymbolicXYItemLabelGenerator g1 = new SymbolicXYItemLabelGenerator();
    SymbolicXYItemLabelGenerator g2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(g1);
        out.close();

        ObjectInput in = new ObjectInputStream(
            new ByteArrayInputStream(buffer.toByteArray())
        );
        g2 = (SymbolicXYItemLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(g1, g2);
}
 
Example 26
Project: jdk8u_jdk   File: JScrollPane.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * See <code>readObject</code> and <code>writeObject</code> in
 * <code>JComponent</code> for more
 * information about serialization in Swing.
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    s.defaultWriteObject();
    if (getUIClassID().equals(uiClassID)) {
        byte count = JComponent.getWriteObjCounter(this);
        JComponent.setWriteObjCounter(this, --count);
        if (count == 0 && ui != null) {
            ui.installUI(this);
        }
    }
}
 
Example 27
Project: dremio-oss   File: IcebergSerDe.java    License: Apache License 2.0 5 votes vote down vote up
private static byte[] serializeToByteArray(Object object) throws IOException {
  try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(bos)) {
    out.writeObject(object);
    return bos.toByteArray();
  }
}
 
Example 28
Project: letv   File: ax.java    License: Apache License 2.0 5 votes vote down vote up
private void a(ObjectOutputStream objectOutputStream) throws IOException {
    try {
        b(new cs(new dk((OutputStream) objectOutputStream)));
    } catch (cf e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 29
Project: dragonwell8_jdk   File: Cons.java    License: 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 30
Project: camunda-bpm-platform   File: JavaSerializationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testJavaObjectNotDeserializedIfNotRequested() throws Exception {

  // this test makes sure that if a serialized value is set, it is not automatically deserialized if deserialization is not requested

  // given
  // a serialized Java Object
  FailingJavaSerializable javaSerializable = new FailingJavaSerializable("foo");
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  new ObjectOutputStream(baos).writeObject(javaSerializable);
  byte[] serializedObjectBytes = baos.toByteArray();
  String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(serializedObjectBytes), engineRule.getProcessEngine());

  thrown.expect(RuntimeException.class);
  thrown.expectMessage("Exception while deserializing object");

  // which cannot be deserialized
  ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(serializedObjectBytes));
  objectInputStream.readObject();

  // if
  // I start a process instance in which a Java Delegate reads the value in its serialized form
  runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables()
    .putValue("varName", serializedObjectValue(serializedObject)
      .serializationDataFormat(JAVA_DATA_FORMAT)
      .objectTypeName(JavaSerializable.class.getName())
      .create()));

  // then
  // it does not fail
}
 
Example 31
Project: jdk1.8-source-analysis   File: BeanContextServicesSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * called from BeanContextSupport writeObject before it serializes the
 * children ...
 *
 * This class will serialize any Serializable BeanContextServiceProviders
 * herein.
 *
 * subclasses may envelope this method to insert their own serialization
 * processing that has to occur prior to serialization of the children
 */

protected synchronized void bcsPreSerializationHook(ObjectOutputStream oos) throws IOException {

    oos.writeInt(serializable);

    if (serializable <= 0) return;

    int count = 0;

    Iterator i = services.entrySet().iterator();

    while (i.hasNext() && count < serializable) {
        Map.Entry           entry = (Map.Entry)i.next();
        BCSSServiceProvider bcsp  = null;

         try {
            bcsp = (BCSSServiceProvider)entry.getValue();
         } catch (ClassCastException cce) {
            continue;
         }

         if (bcsp.getServiceProvider() instanceof Serializable) {
            oos.writeObject(entry.getKey());
            oos.writeObject(bcsp);
            count++;
         }
    }

    if (count != serializable)
        throw new IOException("wrote different number of service providers than expected");
}
 
Example 32
Project: barleydb   File: Entity.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeObject(ObjectOutputStream oos) throws IOException {
    LOG.trace("Serializing entity {}", this);
    oos.writeObject(entityContext);
    oos.writeObject(entityState);
    oos.writeObject(constraints);
    oos.writeUTF(entityType.getInterfaceName());
    oos.writeObject(uuid);
    oos.writeObject(getKey().getValue());
    oos.writeObject(children);
}
 
Example 33
Project: concierge   File: BundlePermission.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private synchronized void writeObject(ObjectOutputStream out) throws IOException {
	Hashtable<String, BundlePermission> hashtable = new Hashtable<String, BundlePermission>(permissions);
	ObjectOutputStream.PutField pfields = out.putFields();
	pfields.put("permissions", hashtable);
	pfields.put("all_allowed", all_allowed);
	out.writeFields();
}
 
Example 34
Project: SIMVA-SoS   File: LegendItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Provides serialization support.
 *
 * @param stream  the output stream (<code>null</code> not permitted).
 *
 * @throws IOException  if there is an I/O error.
 */
private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    SerialUtilities.writeAttributedString(this.attributedLabel, stream);
    SerialUtilities.writeShape(this.shape, stream);
    SerialUtilities.writePaint(this.fillPaint, stream);
    SerialUtilities.writeStroke(this.outlineStroke, stream);
    SerialUtilities.writePaint(this.outlinePaint, stream);
    SerialUtilities.writeShape(this.line, stream);
    SerialUtilities.writeStroke(this.lineStroke, stream);
    SerialUtilities.writePaint(this.linePaint, stream);
    SerialUtilities.writePaint(this.labelPaint, stream);
}
 
Example 35
Project: learnjavabug   File: JavaSerialization.java    License: MIT License 5 votes vote down vote up
private static byte[] object1_() throws IOException {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  ObjectOutputStream out = new ObjectOutputStream(bos);
  out.writeBytes("test");
  out.close();
  return bos.toByteArray();
}
 
Example 36
Project: jdk8u-jdk   File: JSplitPane.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * See <code>readObject</code> and <code>writeObject</code> in
 * <code>JComponent</code> for more
 * information about serialization in Swing.
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    s.defaultWriteObject();
    if (getUIClassID().equals(uiClassID)) {
        byte count = JComponent.getWriteObjCounter(this);
        JComponent.setWriteObjCounter(this, --count);
        if (count == 0 && ui != null) {
            ui.installUI(this);
        }
    }
}
 
Example 37
Project: openjdk-jdk8u   File: AbstractTCKTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Object writeThenRead(Object object) throws IOException, ClassNotFoundException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (ObjectOutputStream oos = new ObjectOutputStream(baos) ) {
        oos.writeObject(object);
    }
    try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
        return ois.readObject();
    }
}
 
Example 38
Project: openjdk-jdk9   File: JPasswordField.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * See readObject() and writeObject() in JComponent for more
 * information about serialization in Swing.
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    s.defaultWriteObject();
    if (getUIClassID().equals(uiClassID)) {
        byte count = JComponent.getWriteObjCounter(this);
        JComponent.setWriteObjCounter(this, --count);
        if (count == 0 && ui != null) {
            ui.installUI(this);
        }
    }
}
 
Example 39
Project: astor   File: Crosshair.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Provides serialization support.
 *
 * @param stream  the output stream.
 *
 * @throws IOException  if there is an I/O error.
 */
private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    SerialUtilities.writePaint(this.paint, stream);
    SerialUtilities.writeStroke(this.stroke, stream);
    SerialUtilities.writePaint(this.labelPaint, stream);
    SerialUtilities.writePaint(this.labelBackgroundPaint, stream);
    SerialUtilities.writeStroke(this.labelOutlineStroke, stream);
    SerialUtilities.writePaint(this.labelOutlinePaint, stream);
}
 
Example 40
Project: openjdk-jdk8u-backup   File: NumericShaper.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the {@code NumericShaper.Range} enum-based parameters,
 * if any, to the bit mask-based counterparts and writes this
 * object to the {@code stream}. Any enum constants that have no
 * bit mask-based counterparts are ignored in the conversion.
 *
 * @param stream the output stream to write to
 * @throws IOException if an I/O error occurs while writing to {@code stream}
 * @since 1.7
 */
private void writeObject(ObjectOutputStream stream) throws IOException {
    if (shapingRange != null) {
        int index = Range.toRangeIndex(shapingRange);
        if (index >= 0) {
            key = index;
        }
    }
    if (rangeSet != null) {
        mask |= Range.toRangeMask(rangeSet);
    }
    stream.defaultWriteObject();
}