Search in sources :

Example 21 with ObjectOutput

use of java.io.ObjectOutput in project jPOS by jpos.

the class ISOMsg2Test method testWriteHeaderThrowsNullPointerException.

@Test
public void testWriteHeaderThrowsNullPointerException() throws Throwable {
    ISOMsg iSOVMsg = new ISOVMsg(new ISOMsg(), new ISOVError("testISOMsgDescription", "testISOMsgRejectCode"));
    ObjectOutput out = new ObjectOutputStream(new ByteArrayOutputStream());
    try {
        iSOVMsg.writeHeader(out);
        fail("Expected NullPointerException to be thrown");
    } catch (NullPointerException ex) {
        assertNull("ex.getMessage()", ex.getMessage());
        assertNull("(ISOVMsg) iSOVMsg.header", ((ISOVMsg) iSOVMsg).header);
    }
}
Also used : ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test)

Example 22 with ObjectOutput

use of java.io.ObjectOutput in project Chronicle-Queue by OpenHFT.

the class DuplicateMessageReadTest method write.

private static void write(final ExcerptAppender appender, final Data data) throws Exception {
    try (final DocumentContext dc = appender.writingDocument()) {
        final ObjectOutput out = dc.wire().objectOutput();
        out.writeInt(data.id);
    }
}
Also used : ObjectOutput(java.io.ObjectOutput) DocumentContext(net.openhft.chronicle.wire.DocumentContext)

Example 23 with ObjectOutput

use of java.io.ObjectOutput in project knime-core by knime.

the class PMMLNaiveBayesModelTranslator method setObjectExtension.

/**
 * @param extension the {@link Extension} to write to
 * @param fieldName the filed name
 * @param fieldValue the value
 */
static void setObjectExtension(final Extension extension, final String fieldName, final Object fieldValue) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutput out = null;
    try {
        out = new ObjectOutputStream(bos);
        out.writeObject(fieldValue);
        byte[] bytes = bos.toByteArray();
        final String valString = new String(Base64.encode(bytes), CharEncoding.UTF_8);
        setStringExtension(extension, fieldName, valString);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException ex) {
        // ignore close exception
        }
        try {
            bos.close();
        } catch (IOException ex) {
        // ignore close exception
        }
    }
}
Also used : ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 24 with ObjectOutput

use of java.io.ObjectOutput in project apex-malhar by apache.

the class HiveStreamCodec method writeExternal.

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    ObjectOutputStream obj = new ObjectOutputStream(os);
    Output output = new Output(obj);
    kryo.writeClassAndObject(output, rollingOperator);
    byte[] outBytes = output.toBytes();
    out.writeInt(outBytes.length);
    out.write(outBytes, 0, outBytes.length);
    out.flush();
}
Also used : Output(com.esotericsoftware.kryo.io.Output) ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 25 with ObjectOutput

use of java.io.ObjectOutput in project drools by kiegroup.

the class KnowledgePackageImpl method writeExternal.

/**
 * Handles the write serialization of the Package. Patterns in Rules may
 * reference generated data which cannot be serialized by default methods.
 * The Package uses PackageCompilationData to hold a reference to the
 * generated bytecode. The generated bytecode must be restored before any
 * Rules.
 *
 * @param stream out the stream to write the object to; should be an instance
 *               of DroolsObjectOutputStream or OutputStream
 */
public void writeExternal(ObjectOutput stream) throws IOException {
    boolean isDroolsStream = stream instanceof DroolsObjectOutputStream;
    ByteArrayOutputStream bytes = null;
    ObjectOutput out;
    if (isDroolsStream) {
        out = stream;
    } else {
        bytes = new ByteArrayOutputStream();
        out = new DroolsObjectOutputStream(bytes);
    }
    out.writeObject(this.name);
    out.writeObject(this.classFieldAccessorStore);
    out.writeObject(this.dialectRuntimeRegistry);
    out.writeObject(this.typeDeclarations);
    out.writeObject(this.imports);
    out.writeObject(this.staticImports);
    out.writeObject(this.functions);
    out.writeObject(this.accumulateFunctions);
    out.writeObject(this.factTemplates);
    out.writeObject(this.ruleFlows);
    out.writeObject(this.globals);
    out.writeBoolean(this.valid);
    out.writeBoolean(this.needStreamMode);
    out.writeObject(this.rules);
    out.writeObject(this.entryPointsIds);
    out.writeObject(this.windowDeclarations);
    out.writeObject(this.traitRegistry);
    out.writeObject(this.resourceTypePackages);
    // writing the whole stream as a byte array
    if (!isDroolsStream) {
        bytes.flush();
        bytes.close();
        stream.writeObject(bytes.toByteArray());
    }
}
Also used : ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DroolsObjectOutputStream(org.drools.core.common.DroolsObjectOutputStream)

Aggregations

ObjectOutput (java.io.ObjectOutput)105 ObjectOutputStream (java.io.ObjectOutputStream)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)64 IOException (java.io.IOException)53 ObjectInput (java.io.ObjectInput)26 Test (org.junit.Test)24 ObjectInputStream (java.io.ObjectInputStream)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 WorkingMemory (org.drools.core.WorkingMemory)13 FileOutputStream (java.io.FileOutputStream)12 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)12 Pattern (org.drools.core.rule.Pattern)12 Consequence (org.drools.core.spi.Consequence)12 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)12 OutputStream (java.io.OutputStream)11 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)8 Declaration (org.drools.core.rule.Declaration)8 IntrospectionException (java.beans.IntrospectionException)7 File (java.io.File)7 InvalidRuleException (org.drools.core.rule.InvalidRuleException)7