com.cmpware.elf
Class ElfOutputStream

java.lang.Object
  extended by com.cmpware.elf.ElfOutputStream

public class ElfOutputStream
extends java.lang.Object

This class is similar to the DataOutputStream but with optional byte swapping performed. This is useful for "endian" conversion when writing an ELF file.

Copyright (c) 2007 Cmpware, Inc. All Rights Reserved.

Author:
SAG

Field Summary
static java.lang.String copyright
          Copyright string
 
Constructor Summary
ElfOutputStream(java.io.OutputStream out)
          The constructor that sets up the ELF Output Stream.
ElfOutputStream(java.io.OutputStream out, boolean byteSwap)
          This constructor that sets up the ELF Output Stream.
ElfOutputStream(java.lang.String filename)
          The constructor that sets up the ELF Output Stream.
 
Method Summary
 void close()
          This method closes the ELF Output Stream.
 int getOffset()
          The method returns the current byte offset into the Elf Output Stream.
 boolean isByteSwap()
          This method returns the current byte swapping status for this Output Stream.
 void set32bit()
          This method sets the default address size to 32 bits.
 void set64bit()
          This method sets the default address size to 64 bits.
 void setByteSwap(boolean b)
          This method sets the byte-swapping flag used by the integer and halfword read methods.
 void write(byte[] b)
          This method writes a byte array to the output stream.
 void writeAddr(long a)
          This method writes an address to the output stream.
 void writeByte(byte b)
          This method writes a byte to the output stream.
 void writeInt(int a)
          This method writes an integer to the output stream and does byte swapping if necessary.
 void writeLong(long a)
          This method writes a long integer to the output stream and does byte swapping if necessary.
 void writeShort(short a)
          This method writes a short to the output stream and does byte swapping if necessary.
 void writeString(java.lang.String s)
          This method writes a String to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyright

public static final java.lang.String copyright
Copyright string

See Also:
Constant Field Values
Constructor Detail

ElfOutputStream

public ElfOutputStream(java.lang.String filename)
                throws java.io.FileNotFoundException
The constructor that sets up the ELF Output Stream.

Parameters:
filename - The file name of the new ELF Output Stream.
Throws:
java.io.FileNotFoundException

ElfOutputStream

public ElfOutputStream(java.io.OutputStream out)
The constructor that sets up the ELF Output Stream.

Parameters:
out - The Output Stream used by the ELF Input Stream.

ElfOutputStream

public ElfOutputStream(java.io.OutputStream out,
                       boolean byteSwap)
This constructor that sets up the ELF Output Stream.

Parameters:
out - The Output Stream used by the ELF Output Stream.
byteSwap - This parameter is set to true if "endian" byte swapping should be used on this input stream and false otherwise.
Method Detail

close

public void close()
           throws java.io.IOException
This method closes the ELF Output Stream.

Throws:
java.io.IOException - if there is an error closing the ELF Outptut Stream.

setByteSwap

public void setByteSwap(boolean b)
This method sets the byte-swapping flag used by the integer and halfword read methods.

Parameters:
b - The boolean flag used to enable byte swapping.

isByteSwap

public boolean isByteSwap()
This method returns the current byte swapping status for this Output Stream. True indicates that byte swapping is enabled, false indicates that no byte swapping occurs on reads.

Returns:
This method returns the current byte swapping status for this Output Stream. True indicates that byte swapping is enabled, false indicates that no byte swapping occurs on reads.

getOffset

public int getOffset()
The method returns the current byte offset into the Elf Output Stream. This is useful for getting offsets used by some data structures.

Returns:
The method returns the current byte offset of the Elf Output Stream.

set32bit

public void set32bit()
This method sets the default address size to 32 bits.


set64bit

public void set64bit()
This method sets the default address size to 64 bits.


writeLong

public void writeLong(long a)
               throws java.io.IOException
This method writes a long integer to the output stream and does byte swapping if necessary.

Parameters:
a - the long value to be written.
Throws:
java.io.IOException - if an error is encountered in writing the Data Output Stream.

writeInt

public void writeInt(int a)
              throws java.io.IOException
This method writes an integer to the output stream and does byte swapping if necessary.

Parameters:
a - the integer to be written.
Throws:
java.io.IOException - if an error is encountered in writing the Data Output Stream.

writeShort

public void writeShort(short a)
                throws java.io.IOException
This method writes a short to the output stream and does byte swapping if necessary.

Parameters:
a - the short value to be written.
Throws:
java.io.IOException - if an error is encountered in writing the Data Output Stream.

writeByte

public void writeByte(byte b)
               throws java.io.IOException
This method writes a byte to the output stream. param b the byte to be written.

Throws:
java.io.IOException - if an error is encountered in writing the Data Output Stream.

write

public void write(byte[] b)
           throws java.io.IOException
This method writes a byte array to the output stream.

Throws:
java.io.IOException - if an error is encountered in writing the Data Output Stream.

writeString

public void writeString(java.lang.String s)
                 throws java.io.IOException
This method writes a String to the output stream.

Parameters:
s - the string to be written.
Throws:
java.io.IOException - if an error is encountered in writing the Data Output Stream.

writeAddr

public void writeAddr(long a)
               throws java.io.IOException
This method writes an address to the output stream. By default this is 32 bits, but can be changed with the setObjectClass() method. Currently only 32 and 64 bit objects / addresses are supported. Note that this method returns a long that may be sign-extended.

Parameters:
a - The address to be written to the output stream.
Throws:
java.io.IOException - if an error is encountered in writing the Data Output Stream.