/** * Reads the next varint encoded int. */ private int readUnsignedVarInt() throws IOException { int value = 0; int shift = 0; int b; do { b = in.read(); value |= (b & 0x7F) << shift; shift += 7; } while ((b & 0x80) != 0); return value; }
/** * Reads the next varint encoded int. */ private int readUnsignedVarInt() throws IOException { int value = 0; int shift = 0; int b; do { b = in.read(); value |= (b & 0x7F) << shift; shift += 7; } while ((b & 0x80) != 0); return value; }
/** * Reads the next byteWidth little endian int. */ private int readIntLittleEndianPaddedOnBitWidth() throws IOException { switch (bytesWidth) { case 0: return 0; case 1: return in.read(); case 2: { int ch2 = in.read(); int ch1 = in.read(); return (ch1 << 8) + ch2; } case 3: { int ch3 = in.read(); int ch2 = in.read(); int ch1 = in.read(); return (ch1 << 16) + (ch2 << 8) + (ch3 << 0); } case 4: { return readIntLittleEndian(); } } throw new RuntimeException("Unreachable"); }
/** * Reads the next byteWidth little endian int. */ private int readIntLittleEndianPaddedOnBitWidth() throws IOException { switch (bytesWidth) { case 0: return 0; case 1: return in.read(); case 2: { int ch2 = in.read(); int ch1 = in.read(); return (ch1 << 8) + ch2; } case 3: { int ch3 = in.read(); int ch2 = in.read(); int ch1 = in.read(); return (ch1 << 16) + (ch2 << 8) + (ch3 << 0); } case 4: { return readIntLittleEndian(); } } throw new RuntimeException("Unreachable"); }
@Override public final boolean readBoolean() { // TODO: vectorize decoding and keep boolean[] instead of currentByte if (bitOffset == 0) { try { currentByte = (byte) in.read(); } catch (IOException e) { throw new ParquetDecodingException("Failed to read a byte", e); } } boolean v = (currentByte & (1 << bitOffset)) != 0; bitOffset += 1; if (bitOffset == 8) { bitOffset = 0; } return v; }
@Override public final boolean readBoolean() { // TODO: vectorize decoding and keep boolean[] instead of currentByte if (bitOffset == 0) { try { currentByte = (byte) in.read(); } catch (IOException e) { throw new ParquetDecodingException("Failed to read a byte", e); } } boolean v = (currentByte & (1 << bitOffset)) != 0; bitOffset += 1; if (bitOffset == 8) { bitOffset = 0; } return v; }
@Override public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException { this.in = in; if (fixedWidth) { // initialize for repetition and definition levels if (readLength) { int length = readIntLittleEndian(); this.in = in.sliceStream(length); } } else { // initialize for values if (in.available() > 0) { init(in.read()); } } if (bitWidth == 0) { // 0 bit width, treat this as an RLE run of valueCount number of 0's. this.mode = MODE.RLE; this.currentCount = valueCount; this.currentValue = 0; } else { this.currentCount = 0; } }
@Override public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException { this.in = in; if (fixedWidth) { // initialize for repetition and definition levels if (readLength) { int length = readIntLittleEndian(); this.in = in.sliceStream(length); } } else { // initialize for values if (in.available() > 0) { init(in.read()); } } if (bitWidth == 0) { // 0 bit width, treat this as an RLE run of valueCount number of 0's. this.mode = MODE.RLE; this.currentCount = valueCount; this.currentValue = 0; } else { this.currentCount = 0; } }
public int read() throws IOException { return delegate.read(); }
public int read(byte[] b, int off, int len) throws IOException { return delegate.read(b, off, len); }
public int read(ByteBuffer out) { return delegate.read(out); }
@Override public int readInteger() { ++ decodedPosition; if (decodedPosition == decoded.length) { try { if (in.available() < bitWidth) { // unpack8Values needs at least bitWidth bytes to read from, // We have to fill in 0 byte at the end of encoded bytes. byte[] tempEncode = new byte[bitWidth]; in.read(tempEncode, 0, in.available()); packer.unpack8Values(tempEncode, 0, decoded, 0); } else { ByteBuffer encoded = in.slice(bitWidth); packer.unpack8Values(encoded, encoded.position(), decoded, 0); } } catch (IOException e) { throw new ParquetDecodingException("Failed to read packed values", e); } decodedPosition = 0; } return decoded[decodedPosition]; }
@Override public int readInteger() { ++ decodedPosition; if (decodedPosition == decoded.length) { try { if (in.available() < bitWidth) { // unpack8Values needs at least bitWidth bytes to read from, // We have to fill in 0 byte at the end of encoded bytes. byte[] tempEncode = new byte[bitWidth]; in.read(tempEncode, 0, in.available()); packer.unpack8Values(tempEncode, 0, decoded, 0); } else { ByteBuffer encoded = in.slice(bitWidth); packer.unpack8Values(encoded, encoded.position(), decoded, 0); } } catch (IOException e) { throw new ParquetDecodingException("Failed to read packed values", e); } decodedPosition = 0; } return decoded[decodedPosition]; }