byte
The default byte order of byte buffer is always BIG_ENDIAN.
119120121122123124125126127128129
fis.read(bb.array()); IntBuffer ib = bb.asIntBuffer(); boolean swap = (ib.get(2) < 0 || ib.get(2) > MAX_NUM_CLASS_PRUNERS); if (swap) { bo = ByteOrder.LITTLE_ENDIAN; bb.order(bo); ib = bb.asIntBuffer(); } int unicharset_size = ib.get(0); int NumClasses = ib.get(1); int NumClassPruners = ib.get(2);
134135136137138139140141142143144
fis.read(bb.array(), 0, 4); NumClasses = ib.get(0); } //this.ClassPruner.ensureCapacity(NumClassPruners); bb = ByteBuffer.allocate(nShortByteSize * unicharset_size); bb.order(bo); fis.read(bb.array()); ShortBuffer sb = bb.asShortBuffer(); for (int i=0; i<unicharset_size; i++) { this.IndexFor[i] = sb.get(i); }
141142143144145146147148149150151
ShortBuffer sb = bb.asShortBuffer(); for (int i=0; i<unicharset_size; i++) { this.IndexFor[i] = sb.get(i); } bb = ByteBuffer.allocate(nIntByteSize * NumClasses); bb.order(bo); fis.read(bb.array()); ib = bb.asIntBuffer(); for (int i=0; i<NumClasses; i++) { this.ClassIdFor[i] = ib.get(i); }
153154155156157158159160161162163
for (int i=0; i<NumClassPruners; i++) { byte[][][][] Pruner = new byte[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][]; bb = ByteBuffer.allocate(nIntByteSize * NUM_CP_BUCKETS * NUM_CP_BUCKETS * NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR); bb.order(bo); fis.read(bb.array()); ib = bb.asIntBuffer(); int p = 0; for (int j=0; j<NUM_CP_BUCKETS; j++) { for (int k=0; k<NUM_CP_BUCKETS; k++) {
7172737475767778798081
LearntFeature(FileInputStream fis, ByteOrder bo) { try { final int nIntByteSize = Integer.SIZE / Byte.SIZE; ByteBuffer bb = ByteBuffer.allocate(4 + nIntByteSize * WERDS_PER_CONFIG_VEC); bb.order(bo); fis.read(bb.array()); this.A = bb.get(0) << 1; // Java doesn't have unsigned byte this.B = unsignedByteToShort(bb.get(1)); this.C = bb.get(2) << 9;
133134135136137138139140141142143
this.mnCutoff = nCutoff; try { final int nIntByteSize = Integer.SIZE / Byte.SIZE; final int nShortByteSize = Short.SIZE / Byte.SIZE; ByteBuffer bb = ByteBuffer.allocate(nShortByteSize + 2); bb.order(bo); fis.read(bb.array()); this.NumProtos = bb.getShort(0); short NumProtoSets = LearntFeature.unsignedByteToShort(bb .get(nShortByteSize)); this.NumConfigs = LearntFeature.unsignedByteToShort(bb
147148149150151152153154155156157
// skip 5 ints bb = ByteBuffer.allocate(5 * nIntByteSize); fis.read(bb.array()); } bb = ByteBuffer.allocate(MAX_NUM_CONFIGS * nShortByteSize); bb.order(bo); fis.read(bb.array()); ShortBuffer sb = bb.asShortBuffer(); for (int i = 0; i < this.ConfigLengths.length; i++) { this.ConfigLengths[i] = sb.get(i); }
158159160161162163164165166167168
this.ProtoLengths = new short[NumProtoSets * Prototype.PROTOS_PER_PROTO_SET]; Arrays.fill(this.ProtoLengths, (short) 0); bb = ByteBuffer.allocate(NumProtoSets * Prototype.PROTOS_PER_PROTO_SET); bb.order(bo); fis.read(bb.array()); for (int i = 0; i < this.NumProtos; i++) { this.ProtoLengths[i] = LearntFeature.unsignedByteToShort(bb.get(i)); } int nProtosLeft = this.NumProtos;
96979899100101102103104105106
public Prototype(FileInputStream fis, ByteOrder bo, int nProtosToRead) { try { final int nIntByteSize = Integer.SIZE / Byte.SIZE; ByteBuffer bb = ByteBuffer.allocate(nIntByteSize * NUM_PP_PARAMS * NUM_PP_BUCKETS * WERDS_PER_PP_VECTOR); bb.order(bo); fis.read(bb.array()); IntBuffer ib = bb.asIntBuffer(); int p = 0; for (int i=0; i<NUM_PP_PARAMS; i++) { for (int j=0; j<NUM_PP_BUCKETS; j++) {
270271272273274275276277278279280
final ByteBuffer buf = truncateBuffer(rcvBuf, datalen); NIOUtils.readFully(channel, buf, datalen); buf.flip(); if(ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { buf.order(ByteOrder.BIG_ENDIAN); } final byte[] b = new byte[datalen]; buf.get(b); if(buf != rcvBuf) { _rbufPool.returnObject(buf);