Class RMData

  • All Implemented Interfaces:
    RMArchiver.Archiving, java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    RMFlashBuffer

    public class RMData
    extends RMObject
    implements java.io.Serializable
    This class is like a StringBuffer for bytes instead of chars. It implements StringBuffer styled append() methods, only everything is forced into ASCII bytes. It is also enhanced with additional binary writing capabilities, so that many core types can be written as binary.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      RMData()
      Creates an empty RMData.
      RMData​(byte[] bytes)
      Creates an RMData with the given byte array.
      RMData​(byte[] bytes, int len)
      Creates an RMData with the given byte array (only to the given length).
      RMData​(int capacity)
      Creates an empty RMData with the given capacity.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      RMData append​(byte[] bytes)
      Appends raw binary from byte array to data.
      RMData append​(byte[] bytes, int offset, int length)
      Appends raw binary from byte array to data.
      RMData append​(char c)
      Append common types as ASCII.
      RMData append​(char[] str)
      Append the given char array.
      RMData append​(char[] str, int offset, int length)
      Appends the given char array.
      RMData append​(double d)
      Appends the given double.
      RMData append​(float f)
      Appends the given float.
      RMData append​(int anInt)
      Appends an int string to the data.
      RMData append​(RMData data)
      Appends raw binary from given data to data.
      RMData append​(java.lang.Object o)
      Appends an object's string representation to the data.
      RMData append​(java.lang.String aString)
      Appends a string to the data.
      void appendByte​(int aByte)
      Appends byte to data.
      void appendInt​(int anInt)
      Appends int to data.
      void appendLittleInt​(int anInt)
      Appends little endian int to data.
      void appendLittleShort​(int aShortInt)
      Appends little endian short to data.
      void appendLittleUInt​(long aUInt)
      Appends little endian unsigned int to data.
      void appendLittleUShort​(int aShort)
      Appends little endian unsigned short to data.
      void appendShort​(int aShortInt)
      Appends short to data.
      void appendUByte​(int aByte)
      Appends unsigned byte to data.
      byte byteAt​(int index)
      Returns the specific byte at the given index.
      int capacity()
      Returns the size of the internal byte array.
      java.lang.Object clone()
      Standard clone implementation.
      void ensureCapacity​(int minimumCapacity)
      Makes sure internal byte array is at least a given size.
      boolean equals​(java.lang.Object anObj)
      Standard equals implementation.
      void flateCompressedData()
      Flate compresses data.
      byte[] getBytes()
      Returns the bytes in the data.
      void getBytes​(int srcBegin, int srcEnd, byte[] destBytes)
      Copies the bytes from this data to the given byte array.
      void getBytes​(int srcBegin, int srcEnd, byte[] destBytes, int destBegin)
      Copies the bytes from this data to the given byte array.
      static RMData getData​(java.lang.Object aSource)
      Returns an RMData for the given File, String path, InputStream, URL, byte[], etc.
      java.lang.Object initWithArchiver​(RMArchiver anArchiver)
      Legacy unarchival.
      java.io.InputStream inputStream()
      Returns an input stream of this data's bytes.
      void insert​(int index, byte[] bytes)
      Inserts raw binary from byte array to data.
      void insert​(int index, byte[] bytes, int offset, int length)
      Inserts raw binary from byte array to data.
      void insert​(int index, RMData data)
      Inserts raw binary from given data to data.
      void insertLittleUIntAtIndex​(long aUInt, int byteIndex)
      Inserts little endian unsigned int to data at given index.
      int length()
      Returns the length of the data.
      void replace​(int start, int end, byte[] bytes, int offset, int length)
      Replace raw binary from byte array in data.
      void setLittleIntAtIndex​(int anInt, int byteIndex)
      Sets little endian int to data at given index.
      void setLittleShortAtIndex​(int aShortInt, int byteIndex)
      Sets little endian short to data at given index.
      void setLittleUShortAtIndex​(int aShort, int byteIndex)
      Sets little endian unsigned short to data at given index.
      byte[] toByteArray()
      Returns a byte array for the bytes in the data.
      byte[] toByteArray​(int start, int end)
      Returns a byte array for the bytes in the data.
      java.lang.String toString()
      Returns the string initialized from the data's bytes (ISO Latin).
      java.lang.String toString​(int start, int end, java.lang.String encoding)
      Returns the string initialized from the data's bytes in the given encoding.
      void writeToFile​(java.lang.String aPath)
      Writes data to file.
      • Methods inherited from class java.lang.Object

        finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • RMData

        public RMData()
        Creates an empty RMData.
      • RMData

        public RMData​(int capacity)
        Creates an empty RMData with the given capacity.
      • RMData

        public RMData​(byte[] bytes)
        Creates an RMData with the given byte array.
      • RMData

        public RMData​(byte[] bytes,
                      int len)
        Creates an RMData with the given byte array (only to the given length).
    • Method Detail

      • getData

        public static RMData getData​(java.lang.Object aSource)
        Returns an RMData for the given File, String path, InputStream, URL, byte[], etc.
      • getBytes

        public byte[] getBytes()
        Returns the bytes in the data.
      • byteAt

        public byte byteAt​(int index)
        Returns the specific byte at the given index.
      • length

        public int length()
        Returns the length of the data.
      • inputStream

        public java.io.InputStream inputStream()
        Returns an input stream of this data's bytes.
      • toByteArray

        public byte[] toByteArray()
        Returns a byte array for the bytes in the data.
      • toByteArray

        public byte[] toByteArray​(int start,
                                  int end)
        Returns a byte array for the bytes in the data.
      • getBytes

        public void getBytes​(int srcBegin,
                             int srcEnd,
                             byte[] destBytes)
        Copies the bytes from this data to the given byte array.
      • getBytes

        public void getBytes​(int srcBegin,
                             int srcEnd,
                             byte[] destBytes,
                             int destBegin)
        Copies the bytes from this data to the given byte array.
      • toString

        public java.lang.String toString()
        Returns the string initialized from the data's bytes (ISO Latin).
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(int start,
                                         int end,
                                         java.lang.String encoding)
        Returns the string initialized from the data's bytes in the given encoding.
      • append

        public RMData append​(char c)
        Append common types as ASCII.
      • append

        public RMData append​(char[] str)
        Append the given char array.
      • append

        public RMData append​(char[] str,
                             int offset,
                             int length)
        Appends the given char array.
      • append

        public RMData append​(double d)
        Appends the given double.
      • append

        public RMData append​(float f)
        Appends the given float.
      • append

        public RMData append​(int anInt)
        Appends an int string to the data.
      • append

        public RMData append​(java.lang.Object o)
        Appends an object's string representation to the data.
      • append

        public RMData append​(java.lang.String aString)
        Appends a string to the data.
      • append

        public RMData append​(RMData data)
        Appends raw binary from given data to data.
      • append

        public RMData append​(byte[] bytes)
        Appends raw binary from byte array to data.
      • append

        public RMData append​(byte[] bytes,
                             int offset,
                             int length)
        Appends raw binary from byte array to data.
      • insert

        public void insert​(int index,
                           RMData data)
        Inserts raw binary from given data to data.
      • insert

        public void insert​(int index,
                           byte[] bytes)
        Inserts raw binary from byte array to data.
      • insert

        public void insert​(int index,
                           byte[] bytes,
                           int offset,
                           int length)
        Inserts raw binary from byte array to data.
      • replace

        public void replace​(int start,
                            int end,
                            byte[] bytes,
                            int offset,
                            int length)
        Replace raw binary from byte array in data.
      • appendByte

        public void appendByte​(int aByte)
        Appends byte to data.
      • appendUByte

        public void appendUByte​(int aByte)
        Appends unsigned byte to data.
      • appendShort

        public void appendShort​(int aShortInt)
        Appends short to data.
      • appendLittleShort

        public void appendLittleShort​(int aShortInt)
        Appends little endian short to data.
      • appendLittleUShort

        public void appendLittleUShort​(int aShort)
        Appends little endian unsigned short to data.
      • appendInt

        public void appendInt​(int anInt)
        Appends int to data.
      • appendLittleInt

        public void appendLittleInt​(int anInt)
        Appends little endian int to data.
      • appendLittleUInt

        public void appendLittleUInt​(long aUInt)
        Appends little endian unsigned int to data.
      • setLittleShortAtIndex

        public void setLittleShortAtIndex​(int aShortInt,
                                          int byteIndex)
        Sets little endian short to data at given index.
      • setLittleUShortAtIndex

        public void setLittleUShortAtIndex​(int aShort,
                                           int byteIndex)
        Sets little endian unsigned short to data at given index.
      • setLittleIntAtIndex

        public void setLittleIntAtIndex​(int anInt,
                                        int byteIndex)
        Sets little endian int to data at given index.
      • insertLittleUIntAtIndex

        public void insertLittleUIntAtIndex​(long aUInt,
                                            int byteIndex)
        Inserts little endian unsigned int to data at given index.
      • flateCompressedData

        public void flateCompressedData()
        Flate compresses data.
      • writeToFile

        public void writeToFile​(java.lang.String aPath)
        Writes data to file.
      • capacity

        public int capacity()
        Returns the size of the internal byte array.
      • ensureCapacity

        public void ensureCapacity​(int minimumCapacity)
        Makes sure internal byte array is at least a given size.
      • equals

        public boolean equals​(java.lang.Object anObj)
        Standard equals implementation.
        Overrides:
        equals in class java.lang.Object
      • clone

        public java.lang.Object clone()
        Standard clone implementation.
        Overrides:
        clone in class RMObject