public Object read (Kryo kryo, Input input, Class type) { // The inflater would read from input beyond the compressed bytes if chunked enoding wasn't used. InflaterInputStream inflaterStream = new InflaterInputStream(new InputChunked(input, 256), new Inflater(noHeaders)); return kryo.readObject(new Input(inflaterStream, 256), type, serializer); }
@Override public T execute(Kryo kryo) { HadoopKryo hkryo = (HadoopKryo) kryo; hkryo.setDataInput(in); T object; if (into) { hkryo.readIntoObject(hkryo.input, outObject); object = outObject; } else { object = (T) hkryo.readClassAndObject(hkryo.input); } hkryo.input.nextChunks(); hkryo.input.close(); return object; } });
/** Advances the stream to the next set of chunks. InputChunked will appear to hit the end of the data until this method is * called. */ public void nextChunks () { if (chunkSize == -1) readChunkSize(); // No current chunk, expect a new chunk. while (chunkSize > 0) skip(chunkSize); chunkSize = -1; if (TRACE) trace("kryo", "Next chunks."); } }
if (inputChunked == null) inputChunked = new InputChunked(input, 1024); inputChunked.nextChunks(); // assume future annexed field and skip if (TRACE) trace(String.format("Unknown field tag: %d (%s) encountered. Assuming a future annexed " + "tag with chunked encoding and skipping.", tag, getType().getName())); throw new KryoException("Unknown field tag: " + tag + " (" + getType().getName() + ")"); } else if (isAnnexed){ if (inputChunked == null) inputChunked = new InputChunked(input, 1024); cachedField.read(inputChunked, object); inputChunked.nextChunks(); } else { cachedField.read(input, object);
protected int fill (byte[] buffer, int offset, int count) throws KryoException { if (chunkSize == -1) // No current chunk, expect a new chunk. readChunkSize(); else if (chunkSize == 0) // End of chunks. return -1; int actual = super.fill(buffer, offset, Math.min(chunkSize, count)); chunkSize -= actual; if (chunkSize == 0) readChunkSize(); // Read next chunk size. return actual; }
private void readChunkSize () { try { InputStream inputStream = getInputStream(); for (int offset = 0, result = 0; offset < 32; offset += 7) { int b = inputStream.read(); if (b == -1) throw new KryoException("Buffer underflow."); result |= (b & 0x7F) << offset; if ((b & 0x80) == 0) { chunkSize = result; if (TRACE) trace("kryo", "Read chunk: " + chunkSize); return; } } } catch (IOException ex) { throw new KryoException(ex); } throw new KryoException("Malformed integer."); }
/** * Initialize reusable objects for reading from given DataInput. * * @param in Input stream */ private void setDataInput(DataInput in) { dataInputWrapperStream.setDataInput(in); input.setInputStream(dataInputWrapperStream); }
if (inputChunked == null) inputChunked = new InputChunked(input, 1024); inputChunked.nextChunks(); // assume future annexed field and skip if (TRACE) trace(String.format("Unknown field tag: %d (%s) encountered. Assuming a future annexed " + "tag with chunked encoding and skipping.", tag, getType().getName())); throw new KryoException("Unknown field tag: " + tag + " (" + getType().getName() + ")"); } else if (isAnnexed){ if (inputChunked == null) inputChunked = new InputChunked(input, 1024); cachedField.read(inputChunked, object); inputChunked.nextChunks(); } else { cachedField.read(input, object);
protected int fill (byte[] buffer, int offset, int count) throws KryoException { if (chunkSize == -1) // No current chunk, expect a new chunk. readChunkSize(); else if (chunkSize == 0) // End of chunks. return -1; int actual = super.fill(buffer, offset, Math.min(chunkSize, count)); chunkSize -= actual; if (chunkSize == 0) readChunkSize(); // Read next chunk size. return actual; }
private void readChunkSize () { try { InputStream inputStream = getInputStream(); for (int offset = 0, result = 0; offset < 32; offset += 7) { int b = inputStream.read(); if (b == -1) throw new KryoException("Buffer underflow."); result |= (b & 0x7F) << offset; if ((b & 0x80) == 0) { chunkSize = result; if (TRACE) trace("kryo", "Read chunk: " + chunkSize); return; } } } catch (IOException ex) { throw new KryoException(ex); } throw new KryoException("Malformed integer."); }
public T read(InputStream in) { KryoContext kryoContext = KRYOS.get(); InputChunked input = kryoContext.getInputChunked(); input.setInputStream(in); return readObject(kryoContext.getKryo(), input); }
InputChunked inputChunked = new InputChunked(input, 1024); for (int i = 0, n = fields.length; i < n; i++) { CachedField cachedField = fields[i]; if (cachedField == null) { if (TRACE) trace("kryo", "Skip obsolete field."); inputChunked.nextChunks(); continue; inputChunked.nextChunks();
/** Advances the stream to the next set of chunks. InputChunked will appear to hit the end of the data until this method is * called. */ public void nextChunks () { if (chunkSize == -1) readChunkSize(); // No current chunk, expect a new chunk. while (chunkSize > 0) skip(chunkSize); chunkSize = -1; if (TRACE) trace("kryo", "Next chunks."); } }
public Object read (Kryo kryo, Input input, Class type) { // The inflater would read from input beyond the compressed bytes if chunked enoding wasn't used. InflaterInputStream inflaterStream = new InflaterInputStream(new InputChunked(input, 256), new Inflater(noHeaders)); return kryo.readObject(new Input(inflaterStream, 256), type, serializer); }
protected int fill (byte[] buffer, int offset, int count) throws KryoException { if (chunkSize == -1) // No current chunk, expect a new chunk. readChunkSize(); else if (chunkSize == 0) // End of chunks. return -1; int actual = super.fill(buffer, offset, Math.min(chunkSize, count)); chunkSize -= actual; if (chunkSize == 0) readChunkSize(); // Read next chunk size. return actual; }
private void readChunkSize () { try { InputStream inputStream = getInputStream(); for (int offset = 0, result = 0; offset < 32; offset += 7) { int b = inputStream.read(); if (b == -1) throw new KryoException("Buffer underflow."); result |= (b & 0x7F) << offset; if ((b & 0x80) == 0) { chunkSize = result; if (TRACE) trace("kryo", "Read chunk: " + chunkSize); return; } } } catch (IOException ex) { throw new KryoException(ex); } throw new KryoException("Malformed integer."); }
InputChunked inputChunked = new InputChunked(input, 1024); boolean hasGenerics = getGenerics() != null; for (int i = 0, n = fields.length; i < n; i++) { inputChunked.nextChunks(); continue; inputChunked.nextChunks();
/** Advances the stream to the next set of chunks. InputChunked will appear to hit the end of the data until this method is * called. */ public void nextChunks () { if (chunkSize == -1) readChunkSize(); // No current chunk, expect a new chunk. while (chunkSize > 0) skip(chunkSize); chunkSize = -1; if (TRACE) trace("kryo", "Next chunks."); } }
public Object read (Kryo kryo, Input input, Class type) { // The inflater would read from input beyond the compressed bytes if chunked enoding wasn't used. Inflater inflater = new Inflater(noHeaders); try { InflaterInputStream inflaterStream = new InflaterInputStream(new InputChunked(input, 256), inflater); return serializer.read(kryo, new Input(inflaterStream, 256), type); } finally { inflater.end(); } }
protected int fill (byte[] buffer, int offset, int count) throws KryoException { if (chunkSize == -1) // No current chunk, expect a new chunk. readChunkSize(); else if (chunkSize == 0) // End of chunks. return -1; int actual = super.fill(buffer, offset, Math.min(chunkSize, count)); chunkSize -= actual; if (chunkSize == 0) readChunkSize(); // Read next chunk size. return actual; }