Class LittleEndianOutputStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
net.simplace.core.io.endian.LittleEndianOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class LittleEndianOutputStream extends FilterOutputStream
Output stream that writes primitive values in little-endian byte order and counts the written bytes.
  • Field Details

    • written

      protected int written
      number of bytes written
  • Constructor Details

    • LittleEndianOutputStream

      public LittleEndianOutputStream(OutputStream out)
      Parameters:
      out - the underlying stream
  • Method Details

    • write

      public void write(int b) throws IOException
      Writes one byte.
      Overrides:
      write in class FilterOutputStream
      Parameters:
      b - the byte (lowest 8 bits)
      Throws:
      IOException - on write errors
    • write

      public void write(byte[] data, int offset, int length) throws IOException
      Writes a part of a byte array.
      Overrides:
      write in class FilterOutputStream
      Parameters:
      data - the bytes
      offset - start index
      length - number of bytes
      Throws:
      IOException - on write errors
    • writeBoolean

      public void writeBoolean(boolean b) throws IOException
      Writes a boolean as 1 byte (1 or 0).
      Parameters:
      b - the value
      Throws:
      IOException - on write errors
    • writeByte

      public void writeByte(int b) throws IOException
      Writes one byte.
      Parameters:
      b - the byte (lowest 8 bits)
      Throws:
      IOException - on write errors
    • writeShort

      public void writeShort(int s) throws IOException
      Writes 2 bytes (little-endian).
      Parameters:
      s - the value (lowest 16 bits)
      Throws:
      IOException - on write errors
    • writeChar

      public void writeChar(int c) throws IOException
      Writes a char as 2 bytes (little-endian).
      Parameters:
      c - the char (lowest 16 bits)
      Throws:
      IOException - on write errors
    • writeInt

      public void writeInt(int i) throws IOException
      Writes 4 bytes (little-endian).
      Parameters:
      i - the value
      Throws:
      IOException - on write errors
    • writeLong

      public void writeLong(long l) throws IOException
      Writes 8 bytes (little-endian).
      Parameters:
      l - the value
      Throws:
      IOException - on write errors
    • writeFloat

      public final void writeFloat(float f) throws IOException
      Writes a float as 4 bytes (little-endian).
      Parameters:
      f - the value
      Throws:
      IOException - on write errors
    • writeDouble

      public final void writeDouble(double d) throws IOException
      Writes a double as 8 bytes (little-endian).
      Parameters:
      d - the value
      Throws:
      IOException - on write errors
    • writeBytes

      public void writeBytes(String s) throws IOException
      Writes the low byte of each character.
      Parameters:
      s - the string
      Throws:
      IOException - on write errors
    • writeChars

      public void writeChars(String s) throws IOException
      Writes each character as 2 bytes (little-endian).
      Parameters:
      s - the string
      Throws:
      IOException - on write errors
    • writeUTF

      public void writeUTF(String s) throws IOException
      Writes a string in modified UTF-8 with a 2 byte length prefix (big-endian, like DataOutput).
      Parameters:
      s - the string
      Throws:
      IOException - if the encoded string is longer than 65535 bytes (UTFDataFormatException) or on write errors
    • size

      public int size()
      Returns:
      the number of bytes written