Class MultipartRequestInputStream

All Implemented Interfaces:
Closeable, AutoCloseable

public class MultipartRequestInputStream extends 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 Details

    • boundary

      protected byte[] boundary
    • lastHeader

      protected FileUploadHeader lastHeader
  • Constructor Details

    • MultipartRequestInputStream

      public MultipartRequestInputStream(InputStream in)
  • Method Details

    • readByte

      public byte readByte() throws IOException
      Reads expected byte. Throws exception on streams end.
      Throws:
      IOException
    • skipBytes

      public void skipBytes(int i) throws IOException
      Skips specified number of bytes.
      Throws:
      IOException
    • readBoundary

      public byte[] readBoundary() throws IOException
      Reads boundary from the input stream.
      Throws:
      IOException
    • getLastHeader

      public FileUploadHeader getLastHeader()
    • readDataHeader

      public FileUploadHeader readDataHeader(String encoding) throws IOException
      Reads data header from the input stream. When there is no more headers (i.e. end of stream reached), returns null
      Throws:
      IOException
    • readDataHeaderString

      protected String readDataHeaderString(String encoding) throws IOException
      Throws:
      IOException
    • copyAll

      public int copyAll(OutputStream out) throws 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:
      IOException
    • copyMax

      public int copyMax(OutputStream out, int maxBytes) throws IOException
      Copies max or less number of bytes to output stream. Useful for determining if uploaded file is larger then expected.
      Throws:
      IOException
    • skipToBoundary

      public int skipToBoundary() throws IOException
      Skips to the boundary and returns total number of bytes skipped.
      Throws:
      IOException
    • isBoundary

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