Class MultipartRequestInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    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

      Fields 
      Modifier and Type Field Description
      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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      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.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • boundary

        protected byte[] boundary
    • 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
      • 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