Package emissary.util.io
Class FastStringBuffer
- java.lang.Object
 - 
- java.io.OutputStream
 - 
- emissary.util.io.FastStringBuffer
 
 
 
- 
- All Implemented Interfaces:
 Closeable,Flushable,AutoCloseable
public class FastStringBuffer extends OutputStream
This buffer implementation attempts to improve file creation performance by preventing conversion from byte array to string and then back to byte array for writing to a stream. The append method here accepts byte arrays and strings. In the case of a byte array it simply copies the bytes. Very fast. In the case of strings it attempts to convert the string to a byte array once and save the results. In this way we avoid converting each time. If many constant string literals are passed to this class, it will be faster. This string buffer will now accept an output stream in addition which allows this string buffer to act as a buffered output stream. 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected byte[]bufferprotected intbytesWrittenprotected intcurPosprotected static org.slf4j.Loggerloggerstatic intMAX_CACHE_SIZEprotected StringmyStringprotected OutputStreamstream 
- 
Constructor Summary
Constructors Constructor Description FastStringBuffer()FastStringBuffer(int initialSize)FastStringBuffer(int initialSize, OutputStream stream)FastStringBuffer(OutputStream stream) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FastStringBufferappend(byte[] a)FastStringBufferappend(byte[] a, int start, int length)FastStringBufferappend(int i)FastStringBufferappend(String s)FastStringBufferappend(String s, String charset)FastStringBufferappendCls(String s)Appends constant string literals only!!!!!FastStringBufferappendCls(String s, String charset)Appends constant string literals only!!!!!FastStringBufferappendCr()FastStringBufferappendCrLf()FastStringBufferappendEscaped(String s)FastStringBufferappendEscaped(String s, String charset)FastStringBufferappendEscapedUtf8(byte[] data, String charset, int start, int end)FastStringBufferappendUtf8(byte[] data, String charset)Write UTF8 data to the output page buffer without specifying a start or end position, defaults to 0,-1FastStringBufferappendUtf8(byte[] data, String charset, int end)Write UTF8 data to the output page buffer without specifying a start position, defaults to 0FastStringBufferappendUtf8(byte[] data, String charset, int start, int end)Write UTF8 data to the output page buffer Pass in 0 and -1 for start and end to do the whole thingvoidclose()voidflush()byte[]getBytes()intgetBytesWritten()intgetSize()voidsetLength(int len)protected byte[]stringToBytes(String s, String charset)StringtoString()voidwrite(byte[] a)voidwrite(byte[] a, int start, int length)voidwrite(int b)- 
Methods inherited from class java.io.OutputStream
nullOutputStream 
 - 
 
 - 
 
- 
- 
Field Detail
- 
logger
protected static final org.slf4j.Logger logger
 
- 
MAX_CACHE_SIZE
public static final int MAX_CACHE_SIZE
- See Also:
 - Constant Field Values
 
 
- 
curPos
protected int curPos
 
- 
buffer
protected byte[] buffer
 
- 
myString
@Nullable protected String myString
 
- 
stream
protected OutputStream stream
 
- 
bytesWritten
protected int bytesWritten
 
 - 
 
- 
Constructor Detail
- 
FastStringBuffer
public FastStringBuffer()
 
- 
FastStringBuffer
public FastStringBuffer(@Nullable OutputStream stream) 
- 
FastStringBuffer
public FastStringBuffer(int initialSize)
 
- 
FastStringBuffer
public FastStringBuffer(int initialSize, @Nullable OutputStream stream) 
 - 
 
- 
Method Detail
- 
append
public FastStringBuffer append(String s) throws IOException
- Throws:
 IOException
 
- 
append
public FastStringBuffer append(int i) throws IOException
- Throws:
 IOException
 
- 
append
public FastStringBuffer append(byte[] a) throws IOException
- Throws:
 IOException
 
- 
append
public FastStringBuffer append(byte[] a, int start, int length) throws IOException
- Throws:
 IOException
 
- 
append
public FastStringBuffer append(@Nullable String s, String charset) throws IOException
- Throws:
 IOException
 
- 
appendEscaped
public FastStringBuffer appendEscaped(String s) throws IOException
- Throws:
 IOException
 
- 
appendEscaped
public FastStringBuffer appendEscaped(@Nullable String s, String charset) throws IOException
- Throws:
 IOException
 
- 
appendCls
public FastStringBuffer appendCls(String s) throws IOException
Appends constant string literals only!!!!!- Throws:
 IOException
 
- 
appendCls
public FastStringBuffer appendCls(@Nullable String s, String charset) throws IOException
Appends constant string literals only!!!!!- Throws:
 IOException
 
- 
appendCr
public FastStringBuffer appendCr() throws IOException
- Throws:
 IOException
 
- 
appendCrLf
public FastStringBuffer appendCrLf() throws IOException
- Throws:
 IOException
 
- 
getBytes
public byte[] getBytes()
 
- 
getSize
public int getSize()
 
- 
setLength
public void setLength(int len)
 
- 
write
public void write(int b) throws IOException- Specified by:
 writein classOutputStream- Throws:
 IOException
 
- 
write
public void write(@Nullable byte[] a) throws IOException- Overrides:
 writein classOutputStream- Throws:
 IOException
 
- 
write
public void write(byte[] a, int start, int length) throws IOException- Overrides:
 writein classOutputStream- Throws:
 IOException
 
- 
flush
public void flush() throws IOException- Specified by:
 flushin interfaceFlushable- Overrides:
 flushin classOutputStream- Throws:
 IOException
 
- 
getBytesWritten
public int getBytesWritten()
 
- 
close
public void close() throws IOException- Specified by:
 closein interfaceAutoCloseable- Specified by:
 closein interfaceCloseable- Overrides:
 closein classOutputStream- Throws:
 IOException
 
- 
appendUtf8
public FastStringBuffer appendUtf8(byte[] data, String charset) throws IOException
Write UTF8 data to the output page buffer without specifying a start or end position, defaults to 0,-1- Throws:
 IOException
 
- 
appendUtf8
public FastStringBuffer appendUtf8(byte[] data, String charset, int end) throws IOException
Write UTF8 data to the output page buffer without specifying a start position, defaults to 0- Throws:
 IOException
 
- 
appendUtf8
public FastStringBuffer appendUtf8(byte[] data, @Nullable String charset, int start, int end) throws IOException
Write UTF8 data to the output page buffer Pass in 0 and -1 for start and end to do the whole thing- Throws:
 IOException
 
- 
appendEscapedUtf8
public FastStringBuffer appendEscapedUtf8(byte[] data, @Nullable String charset, int start, int end) throws IOException
- Throws:
 IOException
 
 - 
 
 -