Skip to content

Commit 56ddd96

Browse files
committed
Appendable BAOS
1 parent 9ace126 commit 56ddd96

File tree

1 file changed

+34
-1
lines changed
  • src/main/java/com/trivago/fastutilconcurrentwrapper/io

1 file changed

+34
-1
lines changed

src/main/java/com/trivago/fastutilconcurrentwrapper/io/BAOS.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
@author Andrej Fink [https://magicprinc.github.io]
5454
*/
5555
@SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod")
56-
public class BAOS extends ByteArrayOutputStream implements RepositionableStream, ObjectOutput, MeasurableStream, SafeCloseable {
56+
public class BAOS extends ByteArrayOutputStream implements RepositionableStream, ObjectOutput, MeasurableStream, SafeCloseable, Appendable {
5757
/// The array backing the output stream.
5858
/// @see #buf
5959
public byte[] array (){ return buf; }
@@ -315,4 +315,37 @@ public void writeObject(Object obj) throws IOException {
315315
oos.flush();
316316
}
317317
}
318+
319+
@Override
320+
public Appendable append (CharSequence csq) {
321+
int len;
322+
if (csq != null && (len = csq.length()) > 0)
323+
append(csq, 0, len);
324+
return this;
325+
}
326+
327+
/// @see #write(byte[], int, int)
328+
/// @see #writeBytes(byte[])
329+
@Override
330+
public Appendable append (CharSequence csq, int start, int end) {
331+
int len = end - start;
332+
Objects.checkFromIndexSize(start, len, csq.length());
333+
if (position + len > buf.length)
334+
buf = ByteArrays.grow(buf, position + len, position);
335+
for (int i = 0; i < len; i++)
336+
buf[position + i] = (byte) csq.charAt(start + i);
337+
position += len;
338+
if (count < position) count = position;
339+
return this;
340+
}
341+
342+
/// @see #writeChar(int)
343+
@Override
344+
public Appendable append (char c) {
345+
grow(2);
346+
JBytes.DirectByteArrayAccess.setChar(buf, position, c);
347+
position += 2;
348+
if (count < position) count = position;
349+
return this;
350+
}
318351
}

0 commit comments

Comments
 (0)