ByteArrayWriterpublic class CharsetAdjustmentWriterDecorator extends Object implements ByteArrayWriter
Unfortunately, String.getBytes() can add a charset header (like a BOM for UTF-16) for every call.
Typically, file based writers call String.getBytes() for each log entry. However, the charset header
should only be written only at the start of a log file and not for each log entry.
| Constructor | Description |
|---|---|
CharsetAdjustmentWriterDecorator(ByteArrayWriter writer,
byte[] charsetHeader) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Closes this writer and releases any associated system resources.
|
void |
flush() |
Forces writing of any buffered data.
|
int |
readTail(byte[] data,
int offset,
int length) |
Reads the last bytes.
|
void |
truncate(int count) |
Truncates the file size.
|
void |
write(byte[] data,
int length) |
Outputs a byte array.
|
void |
write(byte[] data,
int offset,
int length) |
Outputs a byte array.
|
public CharsetAdjustmentWriterDecorator(ByteArrayWriter writer, byte[] charsetHeader)
writer - Underlying writercharsetHeader - Charset header to skippublic int readTail(byte[] data,
int offset,
int length)
throws IOException
ByteArrayWriterThe bytes are read from the end of the current file. If the file size is equal to or greater than the passed length, the passed array is filled completely. Otherwise, the passed array is filled with the entire available file content and all remaining bytes of the array are left untouched.
readTail in interface ByteArrayWriterdata - Target byte array for storing the read bytesoffset - Start offset to fill passed byte arraylength - Maximum number of bytes to readIOException - Reading failedpublic void write(byte[] data,
int length)
throws IOException
ByteArrayWriterwrite in interface ByteArrayWriterdata - Byte array to outputlength - Number of bytes to outputIOException - Writing failedpublic void write(byte[] data,
int offset,
int length)
throws IOException
ByteArrayWriterwrite in interface ByteArrayWriterdata - Byte array to outputoffset - Start offset to outputlength - Number of bytes to outputIOException - Writing failedpublic void truncate(int count)
throws IOException
ByteArrayWritertruncate in interface ByteArrayWritercount - Number of bytes to remove from the file endIOException - Resizing failedpublic void flush()
throws IOException
ByteArrayWriterflush in interface ByteArrayWriterIOException - Writing failedpublic void close()
throws IOException
ByteArrayWriterclose in interface ByteArrayWriterIOException - Closing failedCopyright © 2026. All rights reserved.