FileDocCategorySizeDatePackage
ResettableFileInputStream.javaAPI DocApache James 2.3.14055Fri Jan 12 12:56:34 GMT 2007org.apache.james.util.io

ResettableFileInputStream

public class ResettableFileInputStream extends InputStream
author
Federico Barbieri

Fields Summary
protected static final int
DEFAULT_BUFFER_SIZE
protected final String
m_filename
protected int
m_bufferSize
protected InputStream
m_inputStream
protected long
m_position
protected long
m_mark
protected boolean
m_isMarkSet
Constructors Summary
public ResettableFileInputStream(File file)


         
         
    
        this( file.getCanonicalPath() );
    
public ResettableFileInputStream(String filename)

        this( filename, DEFAULT_BUFFER_SIZE );
    
public ResettableFileInputStream(String filename, int bufferSize)

        m_bufferSize = bufferSize;
        m_filename = filename;
        m_position = 0;

        m_inputStream = newStream();
    
Methods Summary
public intavailable()

        return m_inputStream.available();
    
public voidclose()

        m_inputStream.close();
    
public voidmark(int readLimit)

        m_isMarkSet = true;
        m_mark = m_position;
        m_inputStream.mark( readLimit );
    
public booleanmarkSupported()

        return true;
    
protected java.io.InputStreamnewStream()

        return new BufferedInputStream( new FileInputStream( m_filename ), m_bufferSize );
    
public intread()

        m_position++;
        return m_inputStream.read();
    
public intread(byte[] bytes, int offset, int length)

        final int count = m_inputStream.read( bytes, offset, length );
        m_position += count;
        return count;
    
public voidreset()

        if( !m_isMarkSet )
        {
            throw new IOException( "Unmarked Stream" );
        }
        try
        {
            m_inputStream.reset();
        }
        catch( final IOException ioe )
        {
            try
            {
                m_inputStream.close();
                m_inputStream = newStream();
                m_inputStream.skip( m_mark );
                m_position = m_mark;
            }
            catch( final Exception e )
            {
                throw new IOException( "Cannot reset current Stream: " + e.getMessage() );
            }
        }
    
public longskip(long count)

        m_position += count;
        return m_inputStream.skip( count );