private void readHeaderForNextBlock(DataInputBlobReader<RawDataSchema> inputStream) { if (inputStream.available( ) >= (ChannelReader.PACKED_INT_SIZE + ChannelReader.PACKED_LONG_SIZE) || isEndOfFile || isShuttingDown ) { int orig = inputStream.available(); targetPipeIdx = inputStream.readPackedInt(); targetRemaining = inputStream.readPackedLong(); RawDataSchemaUtil.releaseConsumed(source, inputStream, orig); } }
/** * get the input stream associated with this Pipe and open it * @param pipe Pipe target * @return DataInputBlobReader */ public static <S extends MessageSchema<S>> DataInputBlobReader<S> openInputStream(Pipe<S> pipe) { pipe.blobReader.openLowLevelAPIField(); return pipe.blobReader; }
public static <T extends MessageSchema<T>> int writeBytes(DataOutputBlobWriter<T> writer, DataInputBlobReader<RawDataSchema> reader, int length) { int len = DataInputBlobReader.read(reader, writer.byteBuffer, writer.activePosition, length, writer.byteMask); writer.activePosition+=len; return len; }
/** * Parse a 64 bit signed value */ @Override public long readPackedLong() { long result = readPackedLong(this); assert(storeMostRecentPacked(result)); return result; }
@Override public int readPackedInt() { int result = readPackedInt(this); assert(storeMostRecentPacked(result)); return result; }
@Override public String readUTF() { //use this two line implementation int length = readShort(); //read first 2 byte for length in bytes to convert. return length>=0?readUTFOfLength(length):null; }
/** * Checks to see if passed bytes are equal to field * @param fieldId field to compare * @param utf8EncodedBytes bytes to compare * @return <code>true</code> if equal, else <code>false</code> */ public boolean isEqual(long fieldId, byte[] utf8EncodedBytes) { assert(0==Pipe.structRegistry(DataInputBlobReader.getBackingPipe(channelReader)).dims(fieldId)) : "This method only used for non dim fields."; final int index = channelReader.readFromEndLastInt(StructRegistry.FIELD_MASK&(int)fieldId); if (index>=0) { channelReader.position(index); if (channelReader.available()>=2) { int length = channelReader.readShort(); return utf8EncodedBytes.length==length && channelReader.equalBytes(utf8EncodedBytes); } } return false; }
int absPos = peekInputStream.absolutePosition(); int idx = selector.pickTargetIdx(peekInputStream); peekInputStream.absolutePosition(absPos); peekInputStream.readInto(w,peekInputStream.available()); peekInputStream.readFromEndInto((DataOutputBlobWriter)w); //NOTE: this moves struct across.
/** * Reads int from specified field in pipe * @param association field association showing where to read * @return -1 when absent, else int */ public int readInt(Object association) { return readInt(Pipe.structRegistry(DataInputBlobReader.getBackingPipe(channelReader)).fieldLookupByIdentity(association, DataInputBlobReader.getStructType(channelReader))); }
@Test public void testEncodeString() throws IOException{ //create a new blob pipe to put a string on Pipe<RawDataSchema> pipe = new Pipe<RawDataSchema>(new PipeConfig<RawDataSchema>(RawDataSchema.instance, 100, 4000)); pipe.initBuffers(); DataOutputBlobWriter<RawDataSchema> writer = new DataOutputBlobWriter<RawDataSchema>(pipe); //encode a string on blob using the static method StringBuilder testString = new StringBuilder("This is a test"); PhastEncoder.encodeString(writer, testString , 0, 0, false); writer.close(); //check what is on the pipe DataInputBlobReader<RawDataSchema> reader = new DataInputBlobReader<RawDataSchema>(pipe); //should be -63 int test = reader.readPackedInt(); //the string String value = reader.readUTF(); reader.close(); String s = value.toString(); assertTrue((test==-63) && (s.compareTo("This is a test")==0)); }
@Override public double readDecimalAsDouble() { long m = readPackedLong(); assert(storeMostRecentPacked(m)); if (0!=m) { return Decimal.asDouble(m, readByte()); } else { position++;//must consume last byte (not needed); return wasPackedNull() ? Double.NaN: 0; } }
public static long readUTFAsLong(DataInputBlobReader<?> reader) { return convertTextToLong(reader.parserReader(), reader.backing, reader.position, reader.byteMask, reader.available()); }
public static double readUTFAsDecimal(DataInputBlobReader<?> reader) { return convertTextToDouble(reader.parserReader(), reader.backing, reader.position, reader.available(), reader.byteMask); }
@Override public <A extends Appendable> A readDecimalAsText(A target) { long m = readPackedLong(); assert(storeMostRecentPacked(m)); return Appendables.appendDecimalValue(target, m, readByte()); }
DataInputBlobReader<?> inputStream = Pipe.inputStream(request); inputStream.openLowLevelAPIField(); //path in the stream or all if this is raw if (Pipe.isForSchema(request, FolderWatchSchema.class)) { inputStream.accumLowLevelAPIField(); //name in the stream state.beginFileRead(inputStream.readUTF());
@Override public <A extends Appendable> A readUTFOfLength(int length, A target) { try { return readUTF(this, length, target); } catch (Exception e) { throw new RuntimeException(e); } }
if (dim > 0) { dim--; int c = reader.readPackedInt(); // 2 1 5 0 2 0 if (dim > 0) { final int idx = curPos.length - (1 + dim); int dimPos = reader.absolutePosition(); reader.absolutePosition(curData[0]); curData[0] = reader.absolutePosition(); reader.absolutePosition(dimPos);
protected DataInputBlobReader<T> createNewBlobReader() { return new DataInputBlobReader<T>(this); }
private static <S extends MessageSchema<S>> long readPackedLongB(long a, byte[] buf, int mask, int[] pos, byte v, int depth) { assert(depth<11) : "Error malformed data"; if (depth<11) { //Not checking for this assert because we use NaN for business logic, assert(a!=0 || v!=0) : "malformed data"; return (v >= 0) ? readPackedLong((a | v) << 7, buf, mask, pos, depth) : a | (v & 0x7Fl); } else { logger.warn("malformed data"); return 0; } }