Search in sources :

Example 1 with Input

use of com.esotericsoftware.kryo.io.Input in project storm by apache.

the class KinesisConnectionInfo method getKryoDeserializedObject.

private Object getKryoDeserializedObject(final byte[] ser) {
    final Kryo kryo = new Kryo();
    final Input input = new Input(new ByteArrayInputStream(ser));
    kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
    return kryo.readClassAndObject(input);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) ByteArrayInputStream(java.io.ByteArrayInputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 2 with Input

use of com.esotericsoftware.kryo.io.Input in project hive by apache.

the class KryoSerializer method deserialize.

public static <T> T deserialize(byte[] buffer, Class<T> clazz) {
    Kryo kryo = SerializationUtilities.borrowKryo();
    kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
    T result = null;
    try {
        result = kryo.readObject(new Input(new ByteArrayInputStream(buffer)), clazz);
    } finally {
        SerializationUtilities.releaseKryo(kryo);
    }
    return result;
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 3 with Input

use of com.esotericsoftware.kryo.io.Input in project hive by apache.

the class KeyValueContainer method next.

public ObjectPair<HiveKey, BytesWritable> next() {
    Preconditions.checkState(hasNext());
    if (!readBufferUsed) {
        try {
            if (input == null && output != null) {
                // Close output stream if open
                output.close();
                output = null;
                FileInputStream fis = null;
                try {
                    fis = new FileInputStream(tmpFile);
                    input = new Input(fis);
                } finally {
                    if (input == null && fis != null) {
                        fis.close();
                    }
                }
            }
            if (input != null) {
                // Load next batch from disk
                if (rowsOnDisk >= IN_MEMORY_NUM_ROWS) {
                    rowsInReadBuffer = IN_MEMORY_NUM_ROWS;
                } else {
                    rowsInReadBuffer = rowsOnDisk;
                }
                for (int i = 0; i < rowsInReadBuffer; i++) {
                    ObjectPair<HiveKey, BytesWritable> pair = readBuffer[i];
                    pair.setFirst(readHiveKey(input));
                    pair.setSecond(readValue(input));
                }
                if (input.eof()) {
                    input.close();
                    input = null;
                }
                readBufferUsed = true;
                readCursor = 0;
                rowsOnDisk -= rowsInReadBuffer;
            }
        } catch (Exception e) {
            // Clean up the cache
            clear();
            throw new RuntimeException("Failed to load key/value pairs from disk", e);
        }
    }
    ObjectPair<HiveKey, BytesWritable> row = readBuffer[readCursor];
    if (++readCursor >= rowsInReadBuffer) {
        readBufferUsed = false;
        rowsInReadBuffer = 0;
        readCursor = 0;
    }
    return row;
}
Also used : Input(com.esotericsoftware.kryo.io.Input) HiveKey(org.apache.hadoop.hive.ql.io.HiveKey) BytesWritable(org.apache.hadoop.io.BytesWritable) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException)

Example 4 with Input

use of com.esotericsoftware.kryo.io.Input in project hive by apache.

the class ObjectContainer method next.

public ROW next() {
    Preconditions.checkState(hasNext());
    if (!readBufferUsed) {
        try {
            if (input == null && output != null) {
                // Close output stream if open
                output.close();
                output = null;
                FileInputStream fis = null;
                try {
                    fis = new FileInputStream(tmpFile);
                    input = new Input(fis);
                } finally {
                    if (input == null && fis != null) {
                        fis.close();
                    }
                }
            }
            if (input != null) {
                // Load next batch from disk
                if (rowsOnDisk >= IN_MEMORY_NUM_ROWS) {
                    rowsInReadBuffer = IN_MEMORY_NUM_ROWS;
                } else {
                    rowsInReadBuffer = rowsOnDisk;
                }
                Kryo kryo = SerializationUtilities.borrowKryo();
                try {
                    for (int i = 0; i < rowsInReadBuffer; i++) {
                        readBuffer[i] = (ROW) kryo.readClassAndObject(input);
                    }
                } finally {
                    SerializationUtilities.releaseKryo(kryo);
                }
                if (input.eof()) {
                    input.close();
                    input = null;
                }
                readBufferUsed = true;
                readCursor = 0;
                rowsOnDisk -= rowsInReadBuffer;
            }
        } catch (Exception e) {
            // Clean up the cache
            clear();
            throw new RuntimeException("Failed to load rows from disk", e);
        }
    }
    ROW row = readBuffer[readCursor];
    if (++readCursor >= rowsInReadBuffer) {
        readBufferUsed = false;
        rowsInReadBuffer = 0;
        readCursor = 0;
    }
    return row;
}
Also used : Input(com.esotericsoftware.kryo.io.Input) FileInputStream(java.io.FileInputStream) Kryo(com.esotericsoftware.kryo.Kryo) IOException(java.io.IOException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException)

Example 5 with Input

use of com.esotericsoftware.kryo.io.Input in project hive by apache.

the class FSStatsAggregator method connect.

@Override
public boolean connect(StatsCollectionContext scc) {
    List<String> statsDirs = scc.getStatsTmpDirs();
    assert statsDirs.size() == 1 : "Found multiple stats dirs: " + statsDirs;
    Path statsDir = new Path(statsDirs.get(0));
    LOG.debug("About to read stats from : " + statsDir);
    statsMap = new HashMap<String, Map<String, String>>();
    try {
        fs = statsDir.getFileSystem(scc.getHiveConf());
        statsList = new ArrayList<Map<String, Map<String, String>>>();
        FileStatus[] status = fs.listStatus(statsDir, new PathFilter() {

            @Override
            public boolean accept(Path file) {
                return file.getName().startsWith(StatsSetupConst.STATS_FILE_PREFIX);
            }
        });
        for (FileStatus file : status) {
            Input in = new Input(fs.open(file.getPath()));
            Kryo kryo = SerializationUtilities.borrowKryo();
            try {
                statsMap = kryo.readObject(in, statsMap.getClass());
            } finally {
                SerializationUtilities.releaseKryo(kryo);
            }
            LOG.info("Read stats : " + statsMap);
            statsList.add(statsMap);
            in.close();
        }
        return true;
    } catch (IOException e) {
        LOG.error("Failed to read stats from filesystem ", e);
        return false;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) IOException(java.io.IOException) Input(com.esotericsoftware.kryo.io.Input) HashMap(java.util.HashMap) Map(java.util.Map) Kryo(com.esotericsoftware.kryo.Kryo)

Aggregations

Input (com.esotericsoftware.kryo.io.Input)49 Kryo (com.esotericsoftware.kryo.Kryo)31 Output (com.esotericsoftware.kryo.io.Output)21 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 Test (org.junit.Test)8 Test (org.testng.annotations.Test)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Schema (co.cask.cdap.api.data.schema.Schema)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 ArrayList (java.util.ArrayList)2 HiveKey (org.apache.hadoop.hive.ql.io.HiveKey)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2