1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package org.objectweb.openccm.explorer.util.ior; 26 27 final class ModestInputStream { 28 private byte bytes[]; 29 private int index; 30 private boolean little_endian; 31 public ModestInputStream(byte bytes[]) { 32 this.bytes = bytes; 33 little_endian = bytes[0] != 0; 34 index = 1; 35 } 36 37 public boolean GetEndian() { 38 return little_endian; 39 } 40 41 public byte ReadOctet() { 42 return bytes[index++]; 43 } 44 45 public short ReadUShort() { 46 index += index % 2; 47 48 if (little_endian) { 49 return (short)(((bytes[index++]) & 0x00ff) | ((bytes[index++] << 8) & 0xff00)); 50 } else { 51 return (short)(((bytes[index++] << 8) & 0xff00) | ((bytes[index++]) & 0x00ff)); 52 } 53 } 54 55 public int ReadULong() { 56 int al = index % 4; 57 58 if (al != 0) { 59 index += 4 - al; 60 } 61 62 if (little_endian) { 63 return ((bytes[index++]) & 0x000000ff) | ((bytes[index++] << 8) & 0x0000ff00) | ((bytes[index++] << 16) & 0x00ff0000) | ((bytes[index++] << 24) & 0xff000000); 64 } else { 65 return ((bytes[index++] << 24) & 0xff000000) | ((bytes[index++] << 16) & 0x00ff0000) | ((bytes[index++] << 8) & 0x0000ff00) | ((bytes[index++]) & 0x000000ff); 66 } 67 } 68 69 public String ReadString() { 70 int len = ReadULong() - 1; 71 String str = new String (bytes, index, len); 72 index += len; 73 74 if (ReadOctet() != 0) { 75 throw new org.omg.CORBA.INV_OBJREF ("String should end with byte 0"); 76 } 77 78 return str; 79 } 80 81 public byte[] ReadOctetArray() { 82 int len = ReadULong(); 83 byte b[] = new byte[len]; 84 System.arraycopy(bytes, index, b, 0, len); 85 index += len; 86 return b; 87 } 88 } 89 | Popular Tags |