jodd.servlet.upload
Class MultipartRequestInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.BufferedInputStream
              extended by jodd.servlet.upload.MultipartRequestInputStream
All Implemented Interfaces:
java.io.Closeable

public class MultipartRequestInputStream
extends java.io.BufferedInputStream

Extended input stream based on buffered requests input stream. It provides some more functions that might be useful when working with uploaded fies.


Field Summary
protected  byte[] boundary
           
protected  FileUploadHeader lastHeader
           
 
Fields inherited from class java.io.BufferedInputStream
buf, count, marklimit, markpos, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MultipartRequestInputStream(java.io.InputStream in)
           
 
Method Summary
 int copyAll(java.io.OutputStream out)
          Copies bytes from this stream to some output until boundary is reached.
 int copyMax(java.io.OutputStream out, int maxBytes)
          Copies max or less number of bytes to output stream.
 FileUploadHeader getLastHeader()
           
 boolean isBoundary(byte b)
          Checks if the current byte (i.e. one that was read last) represents the very first byte of the boundary.
 byte[] readBoundary()
          Reads boundary from the input stream.
 byte readByte()
          Reads expected byte.
 FileUploadHeader readDataHeader(java.lang.String encoding)
          Reads data header from the input stream.
protected  java.lang.String readDataHeaderString(java.lang.String encoding)
           
 void skipBytes(int i)
          Skips specified number of bytes.
 int skipToBoundary()
          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
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

boundary

protected byte[] boundary

lastHeader

protected FileUploadHeader lastHeader
Constructor Detail

MultipartRequestInputStream

public MultipartRequestInputStream(java.io.InputStream in)
Method Detail

readByte

public byte readByte()
              throws java.io.IOException
Reads expected byte. Throws exception on streams end.

Throws:
java.io.IOException

skipBytes

public void skipBytes(int i)
               throws java.io.IOException
Skips specified number of bytes.

Throws:
java.io.IOException

readBoundary

public byte[] readBoundary()
                    throws java.io.IOException
Reads 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), returns null

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.IOException
Copies 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.IOException
Copies 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.IOException
Skips to the boundary and returns total number of bytes skipped.

Throws:
java.io.IOException

isBoundary

public boolean isBoundary(byte b)
                   throws java.io.IOException
Checks if the current byte (i.e. one that was read last) represents the very first byte of the boundary.

Throws:
java.io.IOException


Copyright © 2003-2012 Jodd Team