public static String asStringAlways(InputStream in) { if (in == null) { return StringUtils.EMPTY; } try { return asBytes(in).toString(); } catch (IOException ex) { return StringUtils.EMPTY; } }
public void add(byte[] b, int off, int len) { if (len == 0) { return; } int newcount = size + len; checkSize(newcount); try { System.arraycopy(b, off, bytes, size, len); } catch (ArrayIndexOutOfBoundsException ex) { System.err.println(String.format("Copying array of size %d, content %s, off %d, len %d to bytes with len %d at offset %d", b.length, new BytesArray(b), off, len, bytes.length, size)); throw ex; } size = newcount; }
public BytesArray pop() { Entry entry = entries.remove(0); size -= entry.length; byte[] entryData = new byte[entry.length]; System.arraycopy(data.bytes(), entry.offset, entryData, 0, entry.length); return new BytesArray(entryData, entry.length); }
if (retryDataBuffer == null || document.bytes() == retryDataBuffer) { } else { if (ArrayUtils.sliceEquals(document.bytes(), document.offset(), document.length(), retryDataBuffer, 0, retryDataBuffer.length)) { data.copyFrom(newEntry); if (ba.available() < newEntry.length()) { trackingArrayExpanded = true; ba = new BytesArray(new byte[settings.getBatchSizeInBytes()], 0); data = new TrackingBytesArray(ba); } else {
BytesArray doc = new BytesArray(128); doc.add('{'); doc.add(input.bytes(), rangeStart, rangeStop - rangeStart); doc.add(','); doc.add('"'); doc.add(StringUtils.jsonEncoding(metadataField)); doc.add('"'); doc.add(':'); doc.add('{'); doc.add(input.bytes(), rangeStart, rangeStop - rangeStart); bytesPositionIndex += 2; doc.add('}'); doc.add('}'); result[1] = reader.wrapString(doc.toString()); doc.reset();
@Test public void createKeystoreExistsAlreadyOverwrite() throws Exception { TestPrompt console = new TestPrompt(); console.addInput("y"); KeytoolHarness keytool = new KeytoolHarness(console, Keytool.Command.CREATE, true, new BytesArray(128)); assertThat(keytool.run(null, false, false), equalTo(0)); assertThat(console.getOutput(), equalTo("")); assertThat(console.hasInputLeft(), is(false)); assertThat(keytool.ksExists(), is(true)); assertThat(keytool.fileBytes.length(), is(not(0))); }
public void setBytes(byte[] data, int size) { this.data.bytes(data, size); } }
/** * 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(); }
BytesArray entry = new BytesArray(0); while (sq.hasNext()) { hasData = true; entry.reset(); Object[] kv = sq.next(); @SuppressWarnings("unchecked") if (StringUtils.hasText(routing)) { String encodedRouting = StringUtils.jsonEncoding(routing); entry.add(StringUtils.toUTF(String.format(routedFormat, encodedId, encodedRouting))); } else { entry.add(StringUtils.toUTF(String.format(baseFormat, encodedId)));
@Override public void readFields(DataInput in) throws IOException { int size = in.readInt(); byte[] bytes = new byte[size]; in.readFully(bytes, 0, size); ba = new BytesArray(bytes); }
public void add(byte[] b) { if (b == null || b.length == 0) { return; } add(b, 0, b.length); }
@Test public void equalsHashCode() { BytesArray a = new BytesArray(10); BytesArray b = new BytesArray(20); BytesArray c = new BytesArray(""); assertEquals(a, b); assertEquals(b, a); assertEquals(a, c); assertEquals(b, c); assertEquals(c, a); assertEquals(c, b); assertEquals(a.hashCode(), b.hashCode()); assertEquals(a.hashCode(), c.hashCode()); BytesArray d = new BytesArray("test"); BytesArray e = new BytesArray(20); e.add("test"); assertEquals(d, e); assertEquals(e, d); assertEquals(e.hashCode(), d.hashCode()); } }
public void add(int b) { int newcount = size + 1; checkSize(newcount); bytes[size] = (byte) b; size = newcount; }
public void copyFrom(BytesArray from) { addEntry(from.size); from.copyTo(data); }
/** * 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(); }
if (retryDataBuffer == null || document.bytes() == retryDataBuffer) { } else { if (ArrayUtils.sliceEquals(document.bytes(), document.offset(), document.length(), retryDataBuffer, 0, retryDataBuffer.length)) { data.copyFrom(newEntry); if (ba.available() < newEntry.length()) { trackingArrayExpanded = true; ba = new BytesArray(new byte[settings.getBatchSizeInBytes()], 0); data = new TrackingBytesArray(ba); } else {