use of java.io.ObjectOutputStream in project gradle by gradle.
the class PayloadSerializer method serialize.
public SerializedPayload serialize(Object payload) {
final SerializeMap map = classLoaderRegistry.newSerializeSession();
try {
StreamByteBuffer buffer = new StreamByteBuffer();
final ObjectOutputStream objectStream = new PayloadSerializerObjectOutputStream(buffer.getOutputStream(), map);
try {
objectStream.writeObject(payload);
} finally {
IoActions.closeQuietly(objectStream);
}
Map<Short, ClassLoaderDetails> classLoaders = new HashMap<Short, ClassLoaderDetails>();
map.collectClassLoaderDefinitions(classLoaders);
return new SerializedPayload(classLoaders, buffer.readAsListOfByteArrays());
} catch (IOException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
use of java.io.ObjectOutputStream in project grails-core by grails.
the class StreamCharBufferTests method testSerialization.
public void testSerialization() throws Exception {
StreamCharBuffer charBuffer = new StreamCharBuffer();
Writer writer = charBuffer.getWriter();
writer.write("ABCDE");
writer.flush();
// Serialize to a byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(charBuffer);
out.close();
byte[] bytes = bos.toByteArray();
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
charBuffer = (StreamCharBuffer) in.readObject();
assertEquals("ABCDE", charBuffer.toString());
assertEquals(5, charBuffer.size());
charBuffer.getWriter().write("12345");
assertEquals("ABCDE12345", charBuffer.toString());
assertEquals(10, charBuffer.size());
}
use of java.io.ObjectOutputStream in project j2objc by google.
the class AnnotationTypeMismatchExceptionTest method testSerialization.
public void testSerialization() throws Exception {
Method m = String.class.getMethod("length");
AnnotationTypeMismatchException original = new AnnotationTypeMismatchException(m, "poop");
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
// AnnotationTypeMismatchException is broken: it's Serializable but has a non-transient
// non-serializable field of type Method.
new ObjectOutputStream(out).writeObject(original);
fail();
} catch (NotSerializableException expected) {
}
}
use of java.io.ObjectOutputStream in project j2objc by google.
the class SerializationTester method getDeserilizedObject.
/*
* -------------------------------------------------------------------
* Methods
* -------------------------------------------------------------------
*/
/**
* Serialize an object and then deserialize it.
*
* @param inputObject
* the input object
* @return the deserialized object
*/
public static Object getDeserilizedObject(Object inputObject) throws IOException, ClassNotFoundException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(inputObject);
oos.close();
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
Object outputObject = ois.readObject();
lastOutput = outputObject;
ois.close();
return outputObject;
}
use of java.io.ObjectOutputStream in project error-prone by google.
the class RefasterRuleCompilerAnalyzer method finished.
@Override
public void finished(TaskEvent taskEvent) {
if (taskEvent.getKind() != Kind.ANALYZE) {
return;
}
if (JavaCompiler.instance(context).errorCount() > 0) {
return;
}
ClassTree tree = JavacTrees.instance(context).getTree(taskEvent.getTypeElement());
if (tree == null) {
return;
}
Collection<? extends CodeTransformer> rules = RefasterRuleBuilderScanner.extractRules(tree, context);
try (ObjectOutputStream output = new ObjectOutputStream(Files.newOutputStream(destinationPath))) {
output.writeObject(CompositeCodeTransformer.compose(rules));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations