Search in sources :

Example 11 with Output

use of com.esotericsoftware.kryo.io.Output in project apex-core by apache.

the class Journal method setOutputStream.

public void setOutputStream(@Nullable final OutputStream out) throws IOException {
    final Output output;
    if (out != null) {
        output = new Output(4096, -1) {

            @Override
            public void flush() throws KryoException {
                super.flush();
                // Kryo does not flush internal output stream during flush. We need to flush it explicitly.
                try {
                    getOutputStream().flush();
                } catch (IOException e) {
                    throw new KryoException(e);
                }
            }
        };
        output.setOutputStream(out);
    } else {
        output = null;
    }
    final Output oldOut = this.output.getAndSet(output);
    if (oldOut != null && oldOut.getOutputStream() != out) {
        synchronized (oldOut) {
            oldOut.close();
        }
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) Output(com.esotericsoftware.kryo.io.Output) IOException(java.io.IOException)

Example 12 with Output

use of com.esotericsoftware.kryo.io.Output in project apex-core by apache.

the class FSStorageAgent method store.

public static void store(OutputStream stream, Object operator) {
    synchronized (kryo) {
        Output output = new Output(4096, Integer.MAX_VALUE);
        output.setOutputStream(stream);
        kryo.writeClassAndObject(output, operator);
        output.flush();
    }
}
Also used : Output(com.esotericsoftware.kryo.io.Output)

Example 13 with Output

use of com.esotericsoftware.kryo.io.Output in project ignite by apache.

the class KryoSerializer method serialize.

/** {@inheritDoc} */
@Override
public ByteBuffer serialize(Object obj) {
    if (obj == null)
        return null;
    ByteArrayOutputStream stream = null;
    Output out = null;
    try {
        stream = new ByteArrayOutputStream(DFLT_BUFFER_SIZE);
        out = new Output(stream);
        kryos.get().writeClassAndObject(out, obj);
        out.flush();
        return ByteBuffer.wrap(stream.toByteArray());
    } catch (Throwable e) {
        throw new IllegalStateException("Failed to serialize object of the class '" + obj.getClass().getName() + "'", e);
    } finally {
        U.closeQuiet(out);
        U.closeQuiet(stream);
    }
}
Also used : Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 14 with Output

use of com.esotericsoftware.kryo.io.Output in project heron by twitter.

the class HeronPluggableSerializerDelegate method initialize.

@Override
@SuppressWarnings("rawtypes")
public void initialize(Map config) {
    kryo = SerializationFactory.getKryo(config);
    kryoOut = new Output(2000, 2000000000);
    kryoIn = new Input(1);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Output(com.esotericsoftware.kryo.io.Output)

Example 15 with Output

use of com.esotericsoftware.kryo.io.Output in project intellij-community by JetBrains.

the class ExternalProjectSerializer method save.

public void save(@NotNull ExternalProject externalProject) {
    Output output = null;
    try {
        final File externalProjectDir = externalProject.getProjectDir();
        final File configurationFile = getProjectConfigurationFile(new ProjectSystemId(externalProject.getExternalSystemId()), externalProjectDir);
        if (!FileUtil.createParentDirs(configurationFile))
            return;
        output = new Output(new FileOutputStream(configurationFile));
        myKryo.writeObject(output, externalProject);
        LOG.debug("Data saved for imported project from: " + externalProjectDir.getPath());
    } catch (FileNotFoundException e) {
        LOG.error(e);
    } finally {
        StreamUtil.closeStream(output);
    }
}
Also used : Output(com.esotericsoftware.kryo.io.Output) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) File(java.io.File)

Aggregations

Output (com.esotericsoftware.kryo.io.Output)51 Kryo (com.esotericsoftware.kryo.Kryo)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 Input (com.esotericsoftware.kryo.io.Input)21 ByteArrayInputStream (java.io.ByteArrayInputStream)12 Test (org.junit.Test)8 FileOutputStream (java.io.FileOutputStream)7 Test (org.testng.annotations.Test)6 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 KryoException (com.esotericsoftware.kryo.KryoException)4 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 SAMFileHeader (htsjdk.samtools.SAMFileHeader)3 Schema (co.cask.cdap.api.data.schema.Schema)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 StructuredRecord (co.cask.cdap.api.data.format.StructuredRecord)1 ClassIdPair (com.datatorrent.stram.codec.DefaultStatefulStreamCodec.ClassIdPair)1