/* * CVS Identifier: * * $Id: BEBufferedRandomAccessFile.java,v 1.18 2001/07/17 13:13:35 grosbois Exp $ * * Interface: RandomAccessIO.java * * Description: Class for random access I/O (big-endian ordering). * * * * COPYRIGHT: * * This software module was originally developed by Raphaël Grosbois and * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research * Centre France S.A) in the course of development of the JPEG2000 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This * software module is an implementation of a part of the JPEG 2000 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio * Systems AB and Canon Research Centre France S.A (collectively JJ2000 * Partners) agree not to assert against ISO/IEC and users of the JPEG * 2000 Standard (Users) any of their rights under the copyright, not * including other intellectual property rights, for this software module * with respect to the usage by ISO/IEC and Users of this software module * or modifications thereof for use in hardware or software products * claiming conformance to the JPEG 2000 Standard. Those intending to use * this software module in hardware or software products are advised that * their use may infringe existing patents. The original developers of * this software module, JJ2000 Partners and ISO/IEC assume no liability * for use of this software module or modifications thereof. No license * or right to this software module is granted for non JPEG 2000 Standard * conforming products. JJ2000 Partners have full right to use this * software module for his/her own purpose, assign or donate this * software module to any third party and to inhibit third parties from * using this software module for non JPEG 2000 Standard conforming * products. This copyright notice must be included in all copies or * derivative works of this software module. * * Copyright (c) 1999/2000 JJ2000 Partners. * */ using System; namespace CSJ2K.j2k.io { /// This class defines a Buffered Random Access File, where all I/O is /// considered to be big-endian. It extends the /// BufferedRandomAccessFile class. /// /// /// /// /// /// /// /// /// /// /// public class BEBufferedRandomAccessFile:BufferedRandomAccessFile, RandomAccessIO, EndianType { /// Constructor. Always needs a size for the buffer. /// /// /// The file associated with the buffer /// /// /// "r" for read, "rw" or "rw+" for read and write mode ("rw+" /// opens the file for update whereas "rw" removes it /// before. So the 2 modes are different only if the file /// already exists). /// /// /// The number of bytes to buffer /// /// /// If an I/O error ocurred. /// /// public BEBufferedRandomAccessFile(System.IO.FileInfo file, System.String mode, int bufferSize):base(file, mode, bufferSize) { byte_Ordering = CSJ2K.j2k.io.EndianType_Fields.BIG_ENDIAN; } /// Constructor. Uses the default value for the byte-buffer size (512 /// bytes). /// /// /// The file associated with the buffer /// /// /// "r" for read, "rw" or "rw+" for read and write mode ("rw+" /// opens the file for update whereas "rw" removes it /// before. So the 2 modes are different only if the file /// already exists). /// /// /// If an I/O error ocurred. /// /// public BEBufferedRandomAccessFile(System.IO.FileInfo file, System.String mode):base(file, mode) { byte_Ordering = CSJ2K.j2k.io.EndianType_Fields.BIG_ENDIAN; } /// Constructor. Always needs a size for the buffer. /// /// /// The name of the file associated with the buffer /// /// /// "r" for read, "rw" or "rw+" for read and write mode ("rw+" /// opens the file for update whereas "rw" removes it /// before. So the 2 modes are different only if the file /// already exists). /// /// /// The number of bytes to buffer /// /// /// If an I/O error ocurred. /// /// public BEBufferedRandomAccessFile(System.String name, System.String mode, int bufferSize):base(name, mode, bufferSize) { byte_Ordering = CSJ2K.j2k.io.EndianType_Fields.BIG_ENDIAN; } /// Constructor. Uses the default value for the byte-buffer size (512 /// bytes). /// /// /// The name of the file associated with the buffer /// /// /// "r" for read, "rw" or "rw+" for read and write mode ("rw+" /// opens the file for update whereas "rw" removes it /// before. So the 2 modes are different only if the file /// already exists). /// /// /// If an I/O error ocurred. /// /// public BEBufferedRandomAccessFile(System.String name, System.String mode):base(name, mode) { byte_Ordering = CSJ2K.j2k.io.EndianType_Fields.BIG_ENDIAN; } /// Writes the short value of v (i.e., 16 least significant bits) /// to the output. Prior to writing, the output should be realigned at the /// byte level. /// ///

Signed or unsigned data can be written. To write a signed value just /// pass the short value as an argument. To write unsigned data /// pass the int value as an argument (it will be automatically /// casted, and only the 16 least significant bits will be written).

/// ///
/// The value to write to the output /// /// /// If an I/O error ocurred. /// /// public override void writeShort(int v) { write(SupportClass.URShift(v, 8)); write(v); } /// Writes the int value of v (i.e., the 32 bits) to the /// output. Prior to writing, the output should be realigned at the byte /// level. /// /// /// The value to write to the output /// /// /// If an I/O error ocurred. /// /// public override void writeInt(int v) { write(SupportClass.URShift(v, 24)); write(SupportClass.URShift(v, 16)); write(SupportClass.URShift(v, 8)); write(v); } /// Writes the long value of v (i.e., the 64 bits) to the /// output. Prior to writing, the output should be realigned at the byte /// level. /// /// /// The value to write to the output /// /// /// If an I/O error ocurred. /// /// public override void writeLong(long v) { write((int) (SupportClass.URShift(v, 56))); write((int) (SupportClass.URShift(v, 48))); write((int) (SupportClass.URShift(v, 40))); write((int) (SupportClass.URShift(v, 32))); write((int) (SupportClass.URShift(v, 24))); write((int) (SupportClass.URShift(v, 16))); write((int) (SupportClass.URShift(v, 8))); write((int) v); } /// Writes the IEEE float value v (i.e., 32 bits) to the /// output. Prior to writing, the output should be realigned at the byte /// level. /// /// /// The value to write to the output /// /// /// If an I/O error ocurred. /// /// public override void writeFloat(float v) { // CONVERSION PROBLEM? OPTIMIZE!!! //byte[] floatbytes = BitConverter.GetBytes(v); //for (int i = floatbytes.Length-1; i >= 0 ; i--) write(floatbytes[i]); //UPGRADE_ISSUE: Method 'java.lang.Float.floatToIntBits' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangFloatfloatToIntBits_float'" //int intV = Float.floatToIntBits(v); int intV = BitConverter.ToInt32(BitConverter.GetBytes(v), 0); write(SupportClass.URShift(intV, 24)); write(SupportClass.URShift(intV, 16)); write(SupportClass.URShift(intV, 8)); write(intV); } /// Writes the IEEE double value v (i.e., 64 bits) to the /// output. Prior to writing, the output should be realigned at the byte /// level. /// /// /// The value to write to the output /// /// /// If an I/O error ocurred. /// /// public override void writeDouble(double v) { //byte[] doublebytes = BitConverter.GetBytes(v); //for (int i = doublebytes.Length-1; i >= 0 ; i--) write(doublebytes[i]); //UPGRADE_ISSUE: Method 'java.lang.Double.doubleToLongBits' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangDoubledoubleToLongBits_double'" //long longV = Double.doubleToLongBits(v); long longV = BitConverter.ToInt64(BitConverter.GetBytes(v), 0); write((int) (SupportClass.URShift(longV, 56))); write((int) (SupportClass.URShift(longV, 48))); write((int) (SupportClass.URShift(longV, 40))); write((int) (SupportClass.URShift(longV, 32))); write((int) (SupportClass.URShift(longV, 24))); write((int) (SupportClass.URShift(longV, 16))); write((int) (SupportClass.URShift(longV, 8))); write((int) (longV)); } /// Reads a signed short (i.e. 16 bit) from the input. Prior to reading, /// the input should be realigned at the byte level. /// /// /// The next byte-aligned signed short (16 bit) from the input. /// /// /// If the end-of file was reached before /// getting all the necessary data. /// /// /// If an I/O error ocurred. /// /// public override short readShort() { return (short) ((read() << 8) | (read())); } /// Reads an unsigned short (i.e., 16 bit) from the input. It is returned /// as an int since Java does not have an unsigned short /// type. Prior to reading, the input should be realigned at the byte /// level. /// /// /// The next byte-aligned unsigned short (16 bit) from the input, /// as an int. /// /// /// If the end-of file was reached before /// getting all the necessary data. /// /// /// If an I/O error ocurred. /// /// public override int readUnsignedShort() { return ((read() << 8) | read()); } /// Reads a signed int (i.e., 32 bit) from the input. Prior to reading, the /// input should be realigned at the byte level. /// /// /// The next byte-aligned signed int (32 bit) from the input. /// /// /// If the end-of file was reached before /// getting all the necessary data. /// /// /// If an I/O error ocurred. /// /// public override int readInt() { return ((read() << 24) | (read() << 16) | (read() << 8) | read()); } /// Reads an unsigned int (i.e., 32 bit) from the input. It is returned as /// a long since Java does not have an unsigned short type. Prior /// to reading, the input should be realigned at the byte level. /// /// /// The next byte-aligned unsigned int (32 bit) from the input, as /// a long. /// /// /// If the end-of file was reached before /// getting all the necessary data. /// /// /// If an I/O error ocurred. /// /// public override long readUnsignedInt() { return (long) ((read() << 24) | (read() << 16) | (read() << 8) | read()); } /// Reads a signed long (i.e., 64 bit) from the input. Prior to reading, /// the input should be realigned at the byte level. /// /// /// The next byte-aligned signed long (64 bit) from the input. /// /// /// If the end-of file was reached before /// getting all the necessary data. /// /// /// If an I/O error ocurred. /// /// public override long readLong() { //byte[] longbytes = new byte[8]; //for (int i = longbytes.Length-1; i >= 0; i--) longbytes[i] = read(); //return BitConverter.ToInt64(longbytes, 0); return ((long)(((ulong) read() << 56) | ((ulong) read() << 48) | ((ulong) read() << 40) | ((ulong) read() << 32) | ((ulong) read() << 24) | ((ulong) read() << 16) | ((ulong) read() << 8) | ((ulong) read()))); } /// Reads an IEEE single precision (i.e., 32 bit) floating-point number /// from the input. Prior to reading, the input should be realigned at the /// byte level. /// /// /// The next byte-aligned IEEE float (32 bit) from the input. /// /// /// If the end-of file was reached before /// getting all the necessary data. /// /// /// If an I/O error ocurred. /// /// public override float readFloat() { // CONVERSION PROBLEM? OPTIMIZE!!! //byte[] floatbytes = new byte[4]; //for (int i = floatbytes.Length-1; i >= 0 ; i--) floatbytes[i] = (byte)read(); //return BitConverter.ToSingle(floatbytes, 0); //UPGRADE_ISSUE: Method 'java.lang.Float.intBitsToFloat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangFloatintBitsToFloat_int'" //return Float.intBitsToFloat((read() << 24) | (read() << 16) | (read() << 8) | (read())); return BitConverter.ToSingle(BitConverter.GetBytes((read() << 24) | (read() << 16) | (read() << 8) | (read())), 0); } /// Reads an IEEE double precision (i.e., 64 bit) floating-point number /// from the input. Prior to reading, the input should be realigned at the /// byte level. /// /// /// The next byte-aligned IEEE double (64 bit) from the input. /// /// /// If the end-of file was reached before /// getting all the necessary data. /// /// /// If an I/O error ocurred. /// /// public override double readDouble() { // CONVERSION PROBLEM? OPTIMIZE!!! //byte[] doublebytes = new byte[8]; //for (int i = doublebytes.Length-1; i >=0 ; i--) doublebytes[i] = (byte)read(); //return BitConverter.ToDouble(doublebytes, 0); //UPGRADE_ISSUE: Method 'java.lang.Double.longBitsToDouble' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangDoublelongBitsToDouble_long'" //return Double.longBitsToDouble(((long) read() << 56) | ((long) read() << 48) | ((long) read() << 40) | ((long) read() << 32) | ((long) read() << 24) | ((long) read() << 16) | ((long) read() << 8) | ((long) read())); return BitConverter.ToDouble(BitConverter.GetBytes(((long) read() << 56) | ((long) read() << 48) | ((long) read() << 40) | ((long) read() << 32) | ((long) read() << 24) | ((long) read() << 16) | ((long) read() << 8) | ((long) read())), 0); } /// Returns a string of information about the file and the endianess /// /// public override System.String ToString() { return base.ToString() + "\nBig-Endian ordering"; } } }