Package dap4.servlet
Class ChunkWriter
- java.lang.Object
-
- java.io.OutputStream
-
- dap4.servlet.ChunkWriter
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class ChunkWriter extends OutputStream
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classChunkWriter.State
-
Field Summary
Fields Modifier and Type Field Description protected ByteBufferchunkprotected booleanclosedstatic byte[]CRLF8static booleanDEBUGstatic booleanDEBUGHEADERprotected byte[]dmr8static booleanDUMPDATAprotected ByteBufferheaderprotected intmaxbuffersizeprotected dap4.dap4lib.RequestModemodeprotected OutputStreamoutputprotected OutputStreamsaveoutputprotected ChunkWriter.Statestateprotected longwritecountprotected longwritelimitprotected ByteOrderwriteorder
-
Constructor Summary
Constructors Constructor Description ChunkWriter(OutputStream output, dap4.dap4lib.RequestMode mode, ByteOrder writeorder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcacheDMR(dap4.core.dmr.DapDataset dmr, dap4.core.util.DapContext cxt)Cache the DMR.voidcacheDMR(String dmr)static voidchunkheader(int length, int flags, ByteBuffer hdrbuf)voidclose()Closes this output stream and releases any system resources associated with this stream.voidflush()Overload flush to also write out the DMRbyte[]getDump()dap4.dap4lib.RequestModegetMode()ByteOrdergetWriteOrder()voidsetBufferSize(int maxsize)voidsetMode(dap4.dap4lib.RequestMode mode)voidsetWriteLimit(long limit)voidsetWriteOrder(ByteOrder writeorder)voidwrite(byte[] b)Writes b.length bytes from the specified byte array to this output stream.voidwrite(byte[] b, int off, int len)Writes len bytes from the specified byte array starting at offset off to this output stream.voidwrite(int b)Writes the specified byte to the chunkvoidwriteDSR(String dsr)Write the DSR; do not bother to cache.voidwriteError(int httpcode, String msg, String cxt, String other)Write an error chunk.-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Field Detail
-
DEBUG
public static boolean DEBUG
-
DUMPDATA
public static boolean DUMPDATA
-
DEBUGHEADER
public static boolean DEBUGHEADER
-
CRLF8
public static final byte[] CRLF8
-
saveoutput
protected OutputStream saveoutput
-
output
protected OutputStream output
-
state
protected ChunkWriter.State state
-
maxbuffersize
protected int maxbuffersize
-
writelimit
protected long writelimit
-
writecount
protected long writecount
-
chunk
protected ByteBuffer chunk
-
header
protected ByteBuffer header
-
writeorder
protected ByteOrder writeorder
-
mode
protected dap4.dap4lib.RequestMode mode
-
dmr8
protected byte[] dmr8
-
closed
protected boolean closed
-
-
Constructor Detail
-
ChunkWriter
public ChunkWriter(OutputStream output, dap4.dap4lib.RequestMode mode, ByteOrder writeorder) throws IOException
- Throws:
IOException
-
-
Method Detail
-
getMode
public dap4.dap4lib.RequestMode getMode()
-
setMode
public void setMode(dap4.dap4lib.RequestMode mode)
-
setBufferSize
public void setBufferSize(int maxsize)
-
getWriteOrder
public ByteOrder getWriteOrder()
-
setWriteOrder
public void setWriteOrder(ByteOrder writeorder)
-
setWriteLimit
public void setWriteLimit(long limit)
-
writeDSR
public void writeDSR(String dsr) throws IOException
Write the DSR; do not bother to cache.- Parameters:
dsr- The DSR string- Throws:
IOException- on IO related errors
-
cacheDMR
public void cacheDMR(dap4.core.dmr.DapDataset dmr, dap4.core.util.DapContext cxt) throws IOExceptionCache the DMR. What it really does is cache the DMR and write it at the point where it is needed; either in close(), if writing the DMR only, or in writeChunk() if writing data as well.- Parameters:
dmr- The DMR string- Throws:
IOException- on IO related errors
-
cacheDMR
public void cacheDMR(String dmr) throws IOException
- Throws:
IOException
-
writeError
public void writeError(int httpcode, String msg, String cxt, String other) throws IOExceptionWrite an error chunk. If mode == DMR then replaces the dmr else reset the current chunk thus losing any partial write.- Parameters:
httpcode- The httpcode, 0 => ignoremsg- The, null => ignore cxt- The, null => ignore other- The, null => ignore - Throws:
IOException- on IO related errors
-
chunkheader
public static void chunkheader(int length, int flags, ByteBuffer hdrbuf) throws dap4.core.util.DapException- Throws:
dap4.core.util.DapException
-
close
public void close() throws IOExceptionCloses this output stream and releases any system resources associated with this stream. Except, the underlying stream is not actually closed; that is left to the servlet level- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException- on IO related errors
-
getDump
public byte[] getDump()
-
flush
public void flush() throws IOExceptionOverload flush to also write out the DMR- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
write
public void write(byte[] b) throws IOExceptionWrites b.length bytes from the specified byte array to this output stream.- Overrides:
writein classOutputStream- Parameters:
b- the data- Throws:
IOException- if an I/O error occurs
-
write
public void write(int b) throws IOExceptionWrites the specified byte to the chunk- Specified by:
writein classOutputStream- Parameters:
b- the byte to write- Throws:
IOException- if an I/O error occurs
-
write
public void write(byte[] b, int off, int len) throws IOExceptionWrites len bytes from the specified byte array starting at offset off to this output stream.If this write fills up the chunk buffer, then write out the buffer and put the remaining bytes into the reset buffer.
- Overrides:
writein classOutputStream- Parameters:
b- the dataoff- start point in b from which to write datalen- number of bytes to write- Throws:
IOException- if an I/O error occurs
-
-