/** * Creates a new byte array output stream, with a buffer capacity of * the specified size, in bytes. * * @param size the initial size. * @throws EsHadoopIllegalArgumentException if size is negative. */ public FastByteArrayOutputStream(int size) { Assert.isTrue(size >= 0, "Negative initial size: " + size); data = new BytesArray(size); }
private static BytesArray unwrapStreamBuffer(InputStream in) { if (in instanceof FastByteArrayInputStream) { return ((FastByteArrayInputStream) in).data; } if (in instanceof ByteArrayInputStream) { return new BytesArray(byteArrayInputStreamInternalBuffer((ByteArrayInputStream) in)); } return null; }
public String toString() { BytesArray ba = new BytesArray(length()); copyTo(ba); return ba.toString(); } }
@Test public void testAddRefSize() throws Exception { BytesRef ref = new BytesRef(); ref.add(new BytesArray("one")); ref.add(new BytesArray("three")); data.copyFrom(ref); assertEquals(8, data.length()); }
/** * Generate the stream of bytes as hex pairs separated by ' '. */ @Override public String toString() { return (ba != null ? StringUtils.asUTFString(ba.bytes(), 0, ba.length()) : ""); }
@Override protected OutputStream openWrite() throws IOException { this.exists = true; this.fileBytes.reset(); return new FastByteArrayOutputStream(fileBytes); }
private ContentBuilder(Generator generator, ValueWriter writer) { Assert.notNull(generator); this.generator = generator; this.writer = writer; }
/** * Resets the <code>count</code> field of this byte array output * stream to zero, so that all currently accumulated output in the * output stream is discarded. The output stream can be used again, * reusing the already capacity buffer space. * * @see java.io.ByteArrayInputStream#count */ public void reset() { data.reset(); }
/** * Returns the current size of the buffer. * * @return the value of the <code>count</code> field, which is the number * of valid bytes in this output stream. * @see java.io.ByteArrayOutputStream#count */ public long size() { return data.length(); }
public SearchRequestBuilder shard(String shard) { Assert.hasText(shard, "Invalid shard"); this.shard = shard; return this; }
/** * @return the scroll search hit in the original raw JSON format */ public InputStream getHitContents() { return new FastByteArrayInputStream(hit); } }
public String[] getHostNames() { String[] newLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { newLocations[i] = StringUtils.parseIpAddress(locations[i]).ip; } return newLocations; }
public void add(byte[] b) { if (b == null || b.length == 0) { return; } add(b, 0, b.length); }
public void add(int b) { int newcount = size + 1; checkSize(newcount); bytes[size] = (byte) b; size = newcount; }
public void reset() { for (BytesArray ba : pool) { ba.reset(); } inUse = 0; }
/** * @return serialized bulk entry in byte array format */ public InputStream getEntryContents() { return new FastByteArrayInputStream(contents); }