Package com.aoindustries.io.buffer
Class AutoTempFileWriter
- java.lang.Object
-
- java.io.Writer
-
- com.aoindustries.io.buffer.BufferWriter
-
- com.aoindustries.io.buffer.AutoTempFileWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public class AutoTempFileWriter extends BufferWriter
Writes to an initial buffer then switches to a temp file when the threshold is reached. This class is not thread safe.- Author:
- AO Industries, Inc.
-
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_TEMP_FILE_THRESHOLDA reasonable default temp file threshold, currently 4 MB.
-
Constructor Summary
Constructors Constructor Description AutoTempFileWriter(BufferWriter initialBuffer, TempFileContext tempFileContext)Uses the default temp file threshold.AutoTempFileWriter(BufferWriter initialBuffer, TempFileContext tempFileContext, long tempFileThreshold)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AutoTempFileWriterappend(char c)AutoTempFileWriterappend(CharSequence csq)AutoTempFileWriterappend(CharSequence csq, int start, int end)voidclose()voidflush()longgetLength()Gets the number of characters in this buffer.BufferResultgetResult()Gets the result from this buffer.StringtoString()Gets a short message (like type and length).voidwrite(char[] cbuf)voidwrite(char[] cbuf, int off, int len)voidwrite(int c)voidwrite(String str)voidwrite(String str, int off, int len)
-
-
-
Field Detail
-
DEFAULT_TEMP_FILE_THRESHOLD
public static final long DEFAULT_TEMP_FILE_THRESHOLD
A reasonable default temp file threshold, currently 4 MB.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AutoTempFileWriter
public AutoTempFileWriter(BufferWriter initialBuffer, TempFileContext tempFileContext, long tempFileThreshold)
-
AutoTempFileWriter
public AutoTempFileWriter(BufferWriter initialBuffer, TempFileContext tempFileContext)
Uses the default temp file threshold.
-
-
Method Detail
-
write
public void write(int c) throws IOException- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(char[] cbuf) throws IOException- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(char[] cbuf, int off, int len) throws IOException- Specified by:
writein classWriter- Throws:
IOException
-
write
public void write(String str) throws IOException
- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(String str, int off, int len) throws IOException
- Overrides:
writein classWriter- Throws:
IOException
-
append
public AutoTempFileWriter append(CharSequence csq) throws IOException
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
append
public AutoTempFileWriter append(CharSequence csq, int start, int end) throws IOException
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
append
public AutoTempFileWriter append(char c) throws IOException
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
getLength
public long getLength() throws IOExceptionDescription copied from class:BufferWriterGets the number of characters in this buffer. Once closed, this length will not be modified.- Specified by:
getLengthin classBufferWriter- Throws:
IOException
-
toString
public String toString()
Description copied from class:BufferWriterGets a short message (like type and length).- Specified by:
toStringin classBufferWriter- See Also:
To get access to the buffered content.
-
getResult
public BufferResult getResult() throws IllegalStateException, IOException
Description copied from class:BufferWriterGets the result from this buffer. The buffer must be closed.- Specified by:
getResultin classBufferWriter- Throws:
IllegalStateException- if not closedIOException
-
-