Changeset 5864 for branches/cleanup


Ignore:
Timestamp:
02/01/10 06:25:55 (10 years ago)
Author:
callan
Message:

#463 DataTools initial cleanup; removing now unused read/write methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/components/common/src/loci/common/DataTools.java

    r5851 r5864  
    7676  } 
    7777 
    78   /** Reads 1 signed byte [-128, 127]. */ 
    79   public static byte readSignedByte(DataInput in) throws IOException { 
    80     byte[] b = (byte[]) eightBytes.get(); 
    81     in.readFully(b, 0, 1); 
    82     return b[0]; 
    83   } 
    84  
    85   /** Reads 1 unsigned byte [0, 255]. */ 
    86   public static short readUnsignedByte(DataInput in) throws IOException { 
    87     short q = readSignedByte(in); 
    88     if (q < 0) q += 256; 
    89     return q; 
    90   } 
    91  
    92   /** Reads 2 signed bytes [-32768, 32767]. */ 
    93   public static short read2SignedBytes(DataInput in, boolean little) 
    94     throws IOException 
    95   { 
    96     byte[] b = (byte[]) eightBytes.get(); 
    97     in.readFully(b, 0, 2); 
    98     return bytesToShort(b, little); 
    99   } 
    100  
    101   /** Reads 2 unsigned bytes [0, 65535]. */ 
    102   public static int read2UnsignedBytes(DataInput in, boolean little) 
    103     throws IOException 
    104   { 
    105     int q = read2SignedBytes(in, little); 
    106     if (q < 0) q += 65536; 
    107     return q; 
    108   } 
    109  
    110   /** Reads 4 signed bytes [-2147483648, 2147483647]. */ 
    111   public static int read4SignedBytes(DataInput in, boolean little) 
    112     throws IOException 
    113   { 
    114     byte[] b = (byte[]) eightBytes.get(); 
    115     in.readFully(b, 0, 4); 
    116     return bytesToInt(b, little); 
    117   } 
    118  
    119   /** Reads 4 unsigned bytes [0, 4294967296]. */ 
    120   public static long read4UnsignedBytes(DataInput in, boolean little) 
    121     throws IOException 
    122   { 
    123     long q = read4SignedBytes(in, little); 
    124     if (q < 0) q += 4294967296L; 
    125     return q; 
    126   } 
    127  
    128   /** Reads 8 signed bytes [-9223372036854775808, 9223372036854775807]. */ 
    129   public static long read8SignedBytes(DataInput in, boolean little) 
    130     throws IOException 
    131   { 
    132     byte[] b = (byte[]) eightBytes.get(); 
    133     in.readFully(b, 0, 8); 
    134     return bytesToLong(b, little); 
    135   } 
    136  
    137   /** Reads 4 bytes in single precision IEEE format. */ 
    138   public static float readFloat(DataInput in, boolean little) 
    139     throws IOException 
    140   { 
    141     return Float.intBitsToFloat(read4SignedBytes(in, little)); 
    142   } 
    143  
    144   /** Reads 8 bytes in double precision IEEE format. */ 
    145   public static double readDouble(DataInput in, boolean little) 
    146     throws IOException 
    147   { 
    148     return Double.longBitsToDouble(read8SignedBytes(in, little)); 
    149   } 
    150  
    151   // -- Data writing -- 
    152  
    153   /** Writes a string to the given data output destination. */ 
    154   public static void writeString(DataOutput out, String s) 
    155     throws IOException 
    156   { 
    157     byte[] b = s.getBytes("UTF-8"); 
    158     out.write(b); 
    159   } 
    160  
    161   /** Writes a double to the given data output destination. */ 
    162   public static void writeDouble(DataOutput out, double v, boolean little) 
    163     throws IOException 
    164   { 
    165     writeLong(out, Double.doubleToLongBits(v), little); 
    166   } 
    167  
    168   /** Writes a long to the given data output destination. */ 
    169   public static void writeLong(DataOutput out, long v, boolean little) 
    170     throws IOException 
    171   { 
    172     for (int i=0; i<8; i++) { 
    173       int shift = little ? i * 8 : 64 - (i + 1) * 8; 
    174       out.write((int) ((v >>> shift) & 0xff)); 
    175     } 
    176   } 
    177  
    178   /** Writes a float to the given data output destination. */ 
    179   public static void writeFloat(DataOutput out, float v, boolean little) 
    180     throws IOException 
    181   { 
    182     writeInt(out, Float.floatToIntBits(v), little); 
    183   } 
    184  
    185   /** Writes an integer to the given data output destination. */ 
    186   public static void writeInt(DataOutput out, int v, boolean little) 
    187     throws IOException 
    188   { 
    189     for (int i=0; i<4; i++) { 
    190       int shift = little ? i * 8 : 32 - (i + 1) * 8; 
    191       out.write((int) ((v >>> shift) & 0xff)); 
    192     } 
    193   } 
    194  
    195   /** Writes a short to the given data output destination. */ 
    196   public static void writeShort(DataOutput out, int v, boolean little) 
    197     throws IOException 
    198   { 
    199     for (int i=0; i<2; i++) { 
    200       int shift = little ? i * 8 : 16 - (i + 1) * 8; 
    201       out.write((int) ((v >>> shift) & 0xff)); 
    202     } 
    203   } 
    204  
    20578  // -- Word decoding - bytes to primitive types -- 
    20679 
Note: See TracChangeset for help on using the changeset viewer.