org.apache.struts.upload

Class BufferedMultipartInputStream

public class BufferedMultipartInputStream extends InputStream

Deprecated: Use the Commons FileUpload based multipart handler instead. This class will be removed after Struts 1.2.

This class implements buffering for an InputStream as well as a readLine method. The purpose of this is to provide a reliable readLine() method.
Field Summary
protected byte[]buffer
The byte array used to hold buffered data
protected intbufferLength
The number of bytes read from the underlying InputStream that are in the buffer
protected intbufferOffset
The current offset we're at in the buffer's byte array
protected intbufferSize
The size of the byte array buffer
protected longcontentLength
The content length of the multipart data
protected booleancontentLengthMet
Whether or not bytes up to the Content-Length have been read
protected InputStreaminputStream
The underlying InputStream used by this class
protected booleanmaxLengthMet
Whether or not bytes up to the maximum length have been read
protected longmaxSize
The maximum allowed size for the multipart data, or -1 for an unlimited maximum file length
protected inttotalLength
The total number of bytes read so far
Constructor Summary
BufferedMultipartInputStream(InputStream inputStream, int bufferSize, long contentLength, long maxSize)
Public constructor for this class, just wraps the InputStream given
Method Summary
intavailable()
This method returns the number of available bytes left to read in the buffer before it has to be refilled
voidclose()
This method attempts to close the underlying InputStream
booleancontentLengthMet()
protected voidfill()
Fills the buffer with data from the underlying inputStream.
voidmark(int position)
This method calls on the mark() method of the underlying InputStream
booleanmarkSupported()
This method calls on the markSupported() method of the underlying InputStream
booleanmaxLengthMet()
intread()
This method returns the next byte in the buffer, and refills it if necessary.
intread(byte[] b)
This method populates the byte array b with data up to b.length bytes
intread(byte[] b, int offset, int length)
This method populates the byte array b with data up to length starting at b[offset]
intreadLine(byte[] b, int offset, int length)
This method reads into the byte array b until a newline ('\n') character is encountered or the number of bytes specified by length have been read
byte[]readLine()
This method reads a line, regardless of length.
voidreset()
This method makes a call to the reset() method of the underlying InputStream

Field Detail

buffer

protected byte[] buffer
The byte array used to hold buffered data

bufferLength

protected int bufferLength
The number of bytes read from the underlying InputStream that are in the buffer

bufferOffset

protected int bufferOffset
The current offset we're at in the buffer's byte array

bufferSize

protected int bufferSize
The size of the byte array buffer

contentLength

protected long contentLength
The content length of the multipart data

contentLengthMet

protected boolean contentLengthMet
Whether or not bytes up to the Content-Length have been read

inputStream

protected InputStream inputStream
The underlying InputStream used by this class

maxLengthMet

protected boolean maxLengthMet
Whether or not bytes up to the maximum length have been read

maxSize

protected long maxSize
The maximum allowed size for the multipart data, or -1 for an unlimited maximum file length

totalLength

protected int totalLength
The total number of bytes read so far

Constructor Detail

BufferedMultipartInputStream

public BufferedMultipartInputStream(InputStream inputStream, int bufferSize, long contentLength, long maxSize)
Public constructor for this class, just wraps the InputStream given

Parameters: inputStream The underlying stream to read from bufferSize The size in bytes of the internal buffer contentLength The content length for this request maxSize The maximum size in bytes that this multipart request can be, or -1 for an unlimited length

Method Detail

available

public int available()
This method returns the number of available bytes left to read in the buffer before it has to be refilled

close

public void close()
This method attempts to close the underlying InputStream

contentLengthMet

public boolean contentLengthMet()

Returns: true if the content length has been reached, false otherwise

fill

protected void fill()
Fills the buffer with data from the underlying inputStream. If it can't fill the entire buffer in one read, it will read as many times as necessary to fill the buffer

mark

public void mark(int position)
This method calls on the mark() method of the underlying InputStream

markSupported

public boolean markSupported()
This method calls on the markSupported() method of the underlying InputStream

Returns: Whether or not the underlying InputStream supports marking

maxLengthMet

public boolean maxLengthMet()

Returns: true if the maximum length has been reached, false otherwise

read

public int read()
This method returns the next byte in the buffer, and refills it if necessary.

Returns: The next byte read in the buffer, or -1 if the end of the stream has been reached

read

public int read(byte[] b)
This method populates the byte array b with data up to b.length bytes

read

public int read(byte[] b, int offset, int length)
This method populates the byte array b with data up to length starting at b[offset]

readLine

public int readLine(byte[] b, int offset, int length)
This method reads into the byte array b until a newline ('\n') character is encountered or the number of bytes specified by length have been read

readLine

public byte[] readLine()
This method reads a line, regardless of length.

Returns: A byte array representing the line.

reset

public void reset()
This method makes a call to the reset() method of the underlying InputStream
Copyright © 2000-2008 - The Apache Software Foundation