uk.me.parabola.imgfmt.app
Class SectionWriter

java.lang.Object
  extended by uk.me.parabola.imgfmt.app.SectionWriter
All Implemented Interfaces:
java.io.Closeable, ImgFileWriter

public class SectionWriter
extends java.lang.Object
implements ImgFileWriter

A section writer wraps a regular writer so that all the offsets are relative to the start of a section.

Author:
Steve Ratcliffe

Constructor Summary
SectionWriter(ImgFileWriter writer, Section section)
           
 
Method Summary
 void close()
          Note that this does not close the underlying file.
 long getSize()
          Returns the size of the file.
 int position()
          Get the position.
 void position(long pos)
          Set the position of the file.
 void put(byte b)
          Write out a single byte.
 void put(byte[] val)
          Write out an arbitrary length sequence of bytes.
 void put(byte[] src, int start, int length)
          Write out part of a byte array.
 void put3(int val)
          Write out three bytes.
 void putChar(char c)
          Write out two bytes.
 void putInt(int val)
          Write out 4 byte value.
 void sync()
          Called to write out any saved buffers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SectionWriter

public SectionWriter(ImgFileWriter writer,
                     Section section)
Method Detail

sync

public void sync()
          throws java.io.IOException
Description copied from interface: ImgFileWriter
Called to write out any saved buffers. The strategy may write directly to the file in which case this would have nothing or little to do.

Specified by:
sync in interface ImgFileWriter
Throws:
java.io.IOException - If there is an error writing.

close

public void close()
Note that this does not close the underlying file.

Specified by:
close in interface java.io.Closeable

position

public int position()
Description copied from interface: ImgFileWriter
Get the position. Needed because may not be reflected in the underlying file if being buffered.

Specified by:
position in interface ImgFileWriter
Returns:
The logical position within the file.

position

public void position(long pos)
Description copied from interface: ImgFileWriter
Set the position of the file.

Specified by:
position in interface ImgFileWriter
Parameters:
pos - The new position in the file.

put

public void put(byte b)
Description copied from interface: ImgFileWriter
Write out a single byte.

Specified by:
put in interface ImgFileWriter
Parameters:
b - The byte to write.

putChar

public void putChar(char c)
Description copied from interface: ImgFileWriter
Write out two bytes. Done in the correct byte order.

Specified by:
putChar in interface ImgFileWriter
Parameters:
c - The value to write.

put3

public void put3(int val)
Description copied from interface: ImgFileWriter
Write out three bytes. Done in the correct byte order.

Specified by:
put3 in interface ImgFileWriter
Parameters:
val - The value to write, only the bottom three bytes will be written.

putInt

public void putInt(int val)
Description copied from interface: ImgFileWriter
Write out 4 byte value.

Specified by:
putInt in interface ImgFileWriter
Parameters:
val - The value to write.

put

public void put(byte[] val)
Description copied from interface: ImgFileWriter
Write out an arbitrary length sequence of bytes.

Specified by:
put in interface ImgFileWriter
Parameters:
val - The values to write.

put

public void put(byte[] src,
                int start,
                int length)
Description copied from interface: ImgFileWriter
Write out part of a byte array.

Specified by:
put in interface ImgFileWriter
Parameters:
src - The array to take bytes from.
start - The start position.
length - The number of bytes to write.

getSize

public long getSize()
Description copied from interface: ImgFileWriter
Returns the size of the file. Note that this is not a general purpose routine and it may not be possible to give the correct answer at all times.

Specified by:
getSize in interface ImgFileWriter
Returns:
The file size in bytes.