hudson.plugins.testcomplete.mht
Class MHTInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by hudson.plugins.testcomplete.mht.MHTInputStream
All Implemented Interfaces:
Closeable

public class MHTInputStream
extends FilterInputStream

Utility class to read MHT files produced by TestComplete and inspired by inspired by ZipInputStream. This class could also process (though not tested) MHT files produced by other programs.

Author:
Fernando Miguélez Palomo

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MHTInputStream(InputStream in)
          Creates a new MHT input stream and reads the header of the MHT so getBaseUrl() can be called immediately.
 
Method Summary
 int available()
          Returns 0 after EOF has reached for the current entry data, otherwise always return 1.
 void close()
           
 String getBaseUrl()
          Returns the URL all MHT entries are referenced to.
 MHTEntry getNextEntry()
          Returns the next MHTEntry in the stream and positions the stream at the beginning of the entry data.
 MHTEntry getNextEntry(String name)
          Reads the next MHT entry with the name given and positions the stream at the beginning of the entry data.
 void mark(int readlimit)
          This operation is not supported with this input stream and UnsupportedOperationException will be thrown if this method is called.
 boolean markSupported()
           
 int read(byte[] b, int off, int len)
          Reads from the current MHT entry into an array of bytes.
 void reset()
          This operation is not supported with this input stream and UnsupportedOperationException will be thrown if this method is called.
 long skip(long n)
          This operation is not supported with this input stream and UnsupportedOperationException will be thrown if this method is called.
 
Methods inherited from class java.io.FilterInputStream
read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MHTInputStream

public MHTInputStream(InputStream in)
               throws MHTException
Creates a new MHT input stream and reads the header of the MHT so getBaseUrl() can be called immediately.

Parameters:
in - the actual input stream
Throws:
MHTException - if a MHT error has occurred
Method Detail

getBaseUrl

public String getBaseUrl()
Returns the URL all MHT entries are referenced to. This URL is available right after instantiating the stream.

Returns:
the URL all MHT entries are referenced to

getNextEntry

public MHTEntry getNextEntry(String name)
                      throws IOException
Reads the next MHT entry with the name given and positions the stream at the beginning of the entry data. If no entry with such name is found then null is returned and the stream is positioned at EOF.

The name of an entry is considered to be the relative part of the URL stripping out the base URL (as returned by getBaseUrl()). E.g. If an entry has an internal URL http://localhost/index.html and base URL of the stream is http://localhost/ then index.html is the name of the entry.

If the name provided is null next entry in stream is read.

Parameters:
name - the name of the entry to read or null following entry is desired
Returns:
the entry or null if no entry is found with the name provided
Throws:
IOException - if an I/O error has occurred
MHTException - if a MHT error has occurred

getNextEntry

public MHTEntry getNextEntry()
                      throws IOException
Returns the next MHTEntry in the stream and positions the stream at the beginning of the entry data. This is equivalent to calling getNextEntry(String) with null name.

Returns:
the entry or null if no more entries are available.
Throws:
IOException - if an I/O error has occurred
MHTException - if a MHT error has occurred

available

public int available()
              throws IOException
Returns 0 after EOF has reached for the current entry data, otherwise always return 1.

Programs should not count on this method to return the actual number of bytes that could be read without blocking.

Overrides:
available in class FilterInputStream
Returns:
1 before EOF and 0 after EOF has reached for current entry.
Throws:
IOException - if an I/O error has occurred

skip

public long skip(long n)
          throws IOException
This operation is not supported with this input stream and UnsupportedOperationException will be thrown if this method is called.

Overrides:
skip in class FilterInputStream
Throws:
UnsupportedOperationException - if called
IOException

markSupported

public boolean markSupported()
Overrides:
markSupported in class FilterInputStream

mark

public void mark(int readlimit)
This operation is not supported with this input stream and UnsupportedOperationException will be thrown if this method is called.

Overrides:
mark in class FilterInputStream
Throws:
UnsupportedOperationException - if called

reset

public void reset()
           throws IOException
This operation is not supported with this input stream and UnsupportedOperationException will be thrown if this method is called.

Overrides:
reset in class FilterInputStream
Throws:
UnsupportedOperationException - if called
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class FilterInputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads from the current MHT entry into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

Overrides:
read in class FilterInputStream
Parameters:
b - the buffer into which the data is read
off - the start offset in the destination array b
len - the maximum number of bytes read
Throws:
IOException


Copyright © 2004-2015. All Rights Reserved.