FileDocCategorySizeDatePackage
LittleEndianOutputStream.javaAPI DocExample3341Sat Feb 04 07:46:58 GMT 2006com.elharo.io

LittleEndianOutputStream

public class LittleEndianOutputStream extends FilterOutputStream

Fields Summary
protected int
written
Constructors Summary
public LittleEndianOutputStream(OutputStream out)

    super(out);
  
Methods Summary
public intsize()

    return this.written;
  
public voidwrite(int b)

    out.write(b);
    written++;
  
public voidwrite(byte[] data, int offset, int length)

    out.write(data, offset, length);
    written += length;
  
public voidwriteBoolean(boolean b)

  
    if (b) this.write(1);
    else this.write(0);
  
public voidwriteByte(int b)

    out.write(b);
    written++;
  
public voidwriteBytes(java.lang.String s)

    int length = s.length();
    for (int i = 0; i < length; i++) {
      out.write((byte) s.charAt(i));
    }
    written += length;
  
public voidwriteChar(int c)

    out.write(c & 0xFF);
    out.write((c >>> 8) & 0xFF);
    written += 2;
  
public voidwriteChars(java.lang.String s)

    int length = s.length();
    for (int i = 0; i < length; i++) {
      int c = s.charAt(i);
      out.write(c & 0xFF);
      out.write((c >>> 8) & 0xFF);
    }
    written += length * 2;    
  
public final voidwriteDouble(double d)

  
    this.writeLong(Double.doubleToLongBits(d));
  
public final voidwriteFloat(float f)

    this.writeInt(Float.floatToIntBits(f));
  
public voidwriteInt(int i)


    out.write(i & 0xFF);
    out.write((i >>> 8) & 0xFF);
    out.write((i >>> 16) & 0xFF);
    out.write((i >>> 24) & 0xFF);
    written += 4;
    
  
public voidwriteLong(long l)


    out.write((int) l & 0xFF);
    out.write((int) (l >>> 8) & 0xFF);
    out.write((int) (l >>> 16) & 0xFF);
    out.write((int) (l >>> 24) & 0xFF);
    out.write((int) (l >>> 32) & 0xFF);
    out.write((int) (l >>> 40) & 0xFF);
    out.write((int) (l >>> 48) & 0xFF);
    out.write((int) (l >>> 56) & 0xFF);
    written += 8;

  
public voidwriteShort(int s)

    out.write(s & 0xFF);
    out.write((s >>> 8) & 0xFF);
    written += 2;
  
public voidwriteUTF(java.lang.String s)


    int numchars = s.length();
    int numbytes = 0;

    for (int i = 0 ; i < numchars ; i++) {
      int c = s.charAt(i);
      if ((c >= 0x0001) && (c <= 0x007F)) numbytes++;
      else if (c > 0x07FF) numbytes += 3;
      else numbytes += 2;
    }

    if (numbytes > 65535) throw new UTFDataFormatException();     

    out.write((numbytes >>> 8) & 0xFF);
    out.write(numbytes & 0xFF);
    for (int i = 0 ; i < numchars ; i++) {
      int c = s.charAt(i);
      if ((c >= 0x0001) && (c <= 0x007F)) {
        out.write(c);
      }
      else if (c > 0x07FF) {
        out.write(0xE0 | ((c >> 12) & 0x0F));
        out.write(0x80 | ((c >>  6) & 0x3F));
        out.write(0x80 | (c & 0x3F));
        written += 2;
      } 
      else {
        out.write(0xC0 | ((c >>  6) & 0x1F));
        out.write(0x80 | (c & 0x3F));
        written += 1;
      }
    }
    
    written += numchars + 2;