/** Set length in bytes. Should called whenever byte content changes, even * if the length does not change, as this also clears the cached String. * @deprecated call {@link #setByteLength(int)} instead. */ public Utf8 setLength(int newLength) { return setByteLength(newLength); }
/** Set length in bytes. Should called whenever byte content changes, even * if the length does not change, as this also clears the cached String. * @deprecated call {@link #setByteLength(int)} instead. */ public Utf8 setLength(int newLength) { return setByteLength(newLength); }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (length > 0) { in.readFully(result.getBytes(), 0, length); } return result; }
@Override public Utf8 readString(Utf8 old) throws IOException { long length = readLong(); if (length > MAX_ARRAY_SIZE) { throw new UnsupportedOperationException("Cannot read strings longer than " + MAX_ARRAY_SIZE + " bytes"); } if (length < 0L) { throw new AvroRuntimeException("Malformed data. Length is negative: " + length); } Utf8 result = (old != null ? old : new Utf8()); result.setByteLength((int) length); if (0L != length) { doReadBytes(result.getBytes(), 0, (int) length); } return result; }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (0 != length) { doReadBytes(result.getBytes(), 0, length); } return result; }
@Test public void testArrayReusedWhenLargerThanRequestedSize() { byte[] bs = "55555".getBytes(StandardCharsets.UTF_8); Utf8 u = new Utf8(bs); assertEquals(5, u.getByteLength()); byte[] content = u.getBytes(); u.setByteLength(3); assertEquals(3, u.getByteLength()); assertSame(content, u.getBytes()); u.setByteLength(4); assertEquals(4, u.getByteLength()); assertSame(content, u.getBytes()); } }
/** Set length in bytes. Should called whenever byte content changes, even * if the length does not change, as this also clears the cached String. * @deprecated call {@link #setByteLength(int)} instead. */ public Utf8 setLength(int newLength) { return setByteLength(newLength); }
/** Set length in bytes. Should called whenever byte content changes, even * if the length does not change, as this also clears the cached String. * @deprecated call {@link #setByteLength(int)} instead. */ public Utf8 setLength(int newLength) { return setByteLength(newLength); }
/** Set length in bytes. Should called whenever byte content changes, even * if the length does not change, as this also clears the cached String. * @deprecated call {@link #setByteLength(int)} instead. */ public Utf8 setLength(int newLength) { return setByteLength(newLength); }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (length > 0) { in.readFully(result.getBytes(), 0, length); } return result; }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (length > 0) { in.readFully(result.getBytes(), 0, length); } return result; }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (length > 0) { in.readFully(result.getBytes(), 0, length); } return result; }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (length > 0) { in.readFully(result.getBytes(), 0, length); } return result; }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (length > 0) { in.readFully(result.getBytes(), 0, length); } return result; }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (length > 0) { in.readFully(result.getBytes(), 0, length); } return result; }
@Override public Utf8 read(Utf8 reuse) { Utf8 utf8; if (reuse != null) { utf8 = reuse; } else { utf8 = new Utf8(); } // use a byte buffer because it never results in a copy ByteBuffer buffer = column.nextBinary().toByteBuffer(); // always copy the bytes into the Utf8. for constant binary data backed by an array starting // at 0, it is possible to wrap the bytes in a Utf8, but reusing that Utf8 could corrupt the // constant binary if its backing buffer is copied to. utf8.setByteLength(buffer.remaining()); buffer.get(utf8.getBytes(), 0, buffer.remaining()); return utf8; } }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (0 != length) { doReadBytes(result.getBytes(), 0, length); } return result; }
@Override public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); result.setByteLength(length); if (0 != length) { doReadBytes(result.getBytes(), 0, length); } return result; }