1 23 package org.archive.io; 24 25 26 import java.io.EOFException ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 30 31 36 public class Endian { 37 38 39 42 private Endian() { 43 } 44 45 46 54 public static char littleChar(InputStream input) throws IOException { 55 int lo = input.read(); 56 if (lo < 0) { 57 throw new EOFException (); 58 } 59 int hi = input.read(); 60 if (hi < 0) { 61 throw new EOFException (); 62 } 63 return (char)((hi << 8) | lo); 64 } 65 66 67 75 public static short littleShort(InputStream input) throws IOException { 76 return (short)littleChar(input); 77 } 78 79 80 88 public static int littleInt(InputStream input) throws IOException { 89 char lo = littleChar(input); 90 char hi = littleChar(input); 91 return (hi << 16) | lo; 92 } 93 94 95 103 public static char bigChar(InputStream input) throws IOException { 104 int hi = input.read(); 105 if (hi < 0) { 106 throw new EOFException (); 107 } 108 int lo = input.read(); 109 if (lo < 0) { 110 throw new EOFException (); 111 } 112 return (char)((hi << 8) | lo); 113 } 114 115 116 124 public static int bigInt(InputStream input) throws IOException { 125 char hi = bigChar(input); 126 char lo = bigChar(input); 127 return (hi << 16) | lo; 128 } 129 } 130 | Popular Tags |