Package jodd.http.upload
Class MultipartRequestInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- java.io.BufferedInputStream
-
- jodd.http.upload.MultipartRequestInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class MultipartRequestInputStream extends java.io.BufferedInputStreamExtended input stream based on buffered requests input stream. It provides some more functions that might be useful when working with uploaded fies.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]boundaryprotected FileUploadHeaderlastHeader
-
Constructor Summary
Constructors Constructor Description MultipartRequestInputStream(java.io.InputStream in)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcopyAll(java.io.OutputStream out)Copies bytes from this stream to some output until boundary is reached.intcopyMax(java.io.OutputStream out, int maxBytes)Copies max or less number of bytes to output stream.FileUploadHeadergetLastHeader()booleanisBoundary(byte b)Checks if the current byte (i.e.byte[]readBoundary()Reads boundary from the input stream.bytereadByte()Reads expected byte.FileUploadHeaderreadDataHeader(java.lang.String encoding)Reads data header from the input stream.protected java.lang.StringreadDataHeaderString(java.lang.String encoding)voidskipBytes(int i)Skips specified number of bytes.intskipToBoundary()Skips to the boundary and returns total number of bytes skipped.-
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, read, read, reset, skip
-
-
-
-
Field Detail
-
boundary
protected byte[] boundary
-
lastHeader
protected FileUploadHeader lastHeader
-
-
Method Detail
-
readByte
public byte readByte() throws java.io.IOExceptionReads expected byte. Throws exception on streams end.- Throws:
java.io.IOException
-
skipBytes
public void skipBytes(int i) throws java.io.IOExceptionSkips specified number of bytes.- Throws:
java.io.IOException
-
readBoundary
public byte[] readBoundary() throws java.io.IOExceptionReads boundary from the input stream.- Throws:
java.io.IOException
-
getLastHeader
public FileUploadHeader getLastHeader()
-
readDataHeader
public FileUploadHeader readDataHeader(java.lang.String encoding) throws java.io.IOException
Reads data header from the input stream. When there is no more headers (i.e. end of stream reached), returnsnull- Throws:
java.io.IOException
-
readDataHeaderString
protected java.lang.String readDataHeaderString(java.lang.String encoding) throws java.io.IOException- Throws:
java.io.IOException
-
copyAll
public int copyAll(java.io.OutputStream out) throws java.io.IOExceptionCopies bytes from this stream to some output until boundary is reached. Returns number of copied bytes. It will throw an exception for any irregular behaviour.- Throws:
java.io.IOException
-
copyMax
public int copyMax(java.io.OutputStream out, int maxBytes) throws java.io.IOExceptionCopies max or less number of bytes to output stream. Useful for determining if uploaded file is larger then expected.- Throws:
java.io.IOException
-
skipToBoundary
public int skipToBoundary() throws java.io.IOExceptionSkips to the boundary and returns total number of bytes skipped.- Throws:
java.io.IOException
-
isBoundary
public boolean isBoundary(byte b) throws java.io.IOExceptionChecks if the current byte (i.e. one that was read last) represents the very first byte of the boundary.- Throws:
java.io.IOException
-
-