@Override public String getValue(TxnId txnId, ITupleReference tuple) throws AlgebricksException, HyracksDataException { byte[] serRecord = tuple.getFieldData(2); int recordStartOffset = tuple.getFieldStart(2); int recordLength = tuple.getFieldLength(2); ByteArrayInputStream stream = new ByteArrayInputStream(serRecord, recordStartOffset, recordLength); DataInput in = new DataInputStream(stream); try { String nestedType = reader.readUTF(in); if (nestedType.equals(datatypeName)) { recordStartOffset = tuple.getFieldStart(1); recordLength = tuple.getFieldLength(1); stream = new ByteArrayInputStream(serRecord, recordStartOffset, recordLength); in = new DataInputStream(stream); return reader.readUTF(in); } } catch (IOException e) { throw HyracksDataException.create(e); } return null; } }
private void writeAndReadOneString(String testString) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); writer.writeUTF8(testString, dos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray(), 0, bos.size()); assertEquals(testString, reader.readUTF(new DataInputStream(bis))); int lastOffset = bos.size(); char[] charArray = testString.toCharArray(); writer.writeUTF8(charArray, 0, charArray.length, dos); bis = new ByteArrayInputStream(bos.toByteArray(), lastOffset, bos.size()); assertEquals(testString, reader.readUTF(new DataInputStream(bis))); }
@Override public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool) throws HyracksDataException { byte[] b = pointable.getByteArray(); int s = pointable.getStartOffset(); int l = pointable.getLength(); String v; try { v = reader.readUTF(new DataInputStream(new ByteArrayInputStream(b, s + 1, l - 1))); } catch (IOException e) { throw HyracksDataException.create(e); } IJObject jObject = objectPool.allocate(BuiltinType.ASTRING); ((JString) jObject).setValue(v); return jObject; } }
int s = fieldName.getStartOffset(); int l = fieldName.getLength(); String v = reader.readUTF(new DataInputStream(new ByteArrayInputStream(b, s + 1, l - 1))); openFields.put(v, fieldObject);