Example usage for java.io DataInput readShort

List of usage examples for java.io DataInput readShort

Introduction

In this page you can find the example usage for java.io DataInput readShort.

Prototype

short readShort() throws IOException;

Source Link

Document

Reads two input bytes and returns a short value.

Usage

From source file:backup.store.BackupUtil.java

public static String readShortString(DataInput in) throws IOException {
    byte[] buf = new byte[in.readShort()];
    in.readFully(buf);/*w  w  w . j ava  2  s . c  o  m*/
    return new String(buf);
}

From source file:hivemall.fm.FFMPredictionModel.java

@Nonnull
private static void readEntry(@Nonnull final DataInput in, final int factors, @Nonnull final float[] Vf,
        @Nonnull Entry dst) throws IOException {
    final byte type = in.readByte();
    switch (type) {
    case HALF_FLOAT_ENTRY: {
        float W = HalfFloat.halfFloatToFloat(in.readShort());
        dst.setW(W);//w  ww  .j a va 2  s  .  co  m
        for (int i = 0; i < factors; i++) {
            Vf[i] = HalfFloat.halfFloatToFloat(in.readShort());
        }
        dst.setV(Vf);
        break;
    }
    case W_ONLY_HALF_FLOAT_ENTRY: {
        float W = HalfFloat.halfFloatToFloat(in.readShort());
        dst.setW(W);
        break;
    }
    case FLOAT_ENTRY: {
        float W = in.readFloat();
        dst.setW(W);
        IOUtils.readFloats(in, Vf);
        dst.setV(Vf);
        break;
    }
    case W_ONLY_FLOAT_ENTRY: {
        float W = in.readFloat();
        dst.setW(W);
        break;
    }
    default:
        throw new IOException("Unexpected Entry type: " + type);
    }
}

From source file:com.buaa.cfs.fs.permission.FsPermission.java

@Override
public void readFields(DataInput in) throws IOException {
    fromShort(in.readShort());
}

From source file:libra.common.hadoop.io.datatypes.CompressedIntArrayWritable.java

@Override
public void readFields(DataInput in) throws IOException {
    byte flag = in.readByte();
    int count = 0;
    if ((flag & 0x0f) == 0x00) {
        count = in.readByte();// ww  w .  j a  v  a  2 s .com
    } else if ((flag & 0x0f) == 0x01) {
        count = in.readShort();
    } else if ((flag & 0x0f) == 0x02) {
        count = in.readInt();
    } else {
        throw new IOException("unhandled flag");
    }

    this.positiveEntries = 0;
    this.negativeEntries = 0;

    int[] arr = new int[count];
    if ((flag & 0xf0) == 0x00) {
        for (int i = 0; i < count; i++) {
            arr[i] = in.readByte();
            if (arr[i] >= 0) {
                this.positiveEntries++;
            } else {
                this.negativeEntries++;
            }
        }
    } else if ((flag & 0xf0) == 0x10) {
        for (int i = 0; i < count; i++) {
            arr[i] = in.readShort();
            if (arr[i] >= 0) {
                this.positiveEntries++;
            } else {
                this.negativeEntries++;
            }
        }
    } else if ((flag & 0xf0) == 0x20) {
        for (int i = 0; i < count; i++) {
            arr[i] = in.readInt();
            if (arr[i] >= 0) {
                this.positiveEntries++;
            } else {
                this.negativeEntries++;
            }
        }
    } else {
        throw new IOException("unhandled flag");
    }

    this.intArray = arr;
    this.prevBytes = null;
}

From source file:edu.msu.cme.rdp.readseq.readers.core.SFFCore.java

public ReadBlock readReadBlock() throws IOException {
    try {/*from w  w w.  j a v a  2s .  c o m*/
        DataInput seqFile = super.getDataInput();

        ReadBlock ret = new ReadBlock();

        /*
         * READ BLOCK HEADER
         */

        ret.headerLength = seqFile.readShort();
        ret.nameLength = seqFile.readShort();

        int tmp = (ret.headerLength << 16) | ret.nameLength;
        if (tmp == mftMagicNumber) { //We ended up in the index...certainly possible
            return null;
        }

        ret.numBases = seqFile.readInt();
        ret.clipQualLeft = seqFile.readUnsignedShort();
        ret.clipQualRight = seqFile.readUnsignedShort();
        ret.clipAdapterLeft = seqFile.readUnsignedShort();
        ret.clipAdapterRight = seqFile.readUnsignedShort();

        byte[] readName = new byte[ret.nameLength];
        super.read(readName);

        int dataOffset = ret.headerLength - (ret.nameLength + READ_BLOCK_STATIC_SIZE);
        if (dataOffset < 0) {
            throw new IOException("Illegal ReadBlock header length (" + ret.headerLength
                    + "), it would have me seek back in to the readblock");
        }

        seqFile.skipBytes(dataOffset);

        /*
         * READ BLOCK DATA
         */

        byte[] flowgramIndex = new byte[ret.numBases];
        byte[] bases = new byte[ret.numBases];
        byte[] quality = new byte[ret.numBases];

        byte[] homopolymerStretchEstimates = new byte[(commonHeader.flowLength) * 2];

        super.read(homopolymerStretchEstimates);
        super.read(flowgramIndex);
        super.read(bases);
        super.read(quality);

        DataInputStream flowgramStream = new DataInputStream(
                new ByteArrayInputStream(homopolymerStretchEstimates));

        short[] flowgrams = new short[commonHeader.flowLength];
        for (int index = 0; index < commonHeader.flowLength; index++) {
            flowgrams[index] = flowgramStream.readShort();
        }
        flowgramStream.close();

        ret.name = new String(readName);
        ret.flowgrams = flowgrams;
        ret.flowIndex = flowgramIndex;
        ret.seq = new String(bases);
        ret.qual = quality;
        int bytesRead = homopolymerStretchEstimates.length + flowgramIndex.length + bases.length
                + quality.length;

        alignToBoundary(bytesRead);

        return ret;
    } catch (EOFException e) {
        return null;
    }
}

From source file:edu.msu.cme.rdp.readseq.readers.core.SFFCore.java

private void parseCommonHeader() throws IOException {
    if (commonHeader != null) {
        throw new IOException("Common header already initialized");
    }/*from   w  ww  .  ja  v  a2  s  .  c  om*/
    commonHeader = new CommonHeader();

    DataInput seqFile = super.getDataInput();

    commonHeader.magicNumber = seqFile.readInt();

    if (commonHeader.magicNumber != SeqUtils.SFF_MAGIC_NUMBER) {
        throw new IOException("Not an SFF File");
    }

    commonHeader.version = seqFile.readInt();

    if (commonHeader.version != 1) {
        throw new IOException("Cannot parse v" + commonHeader.version + " sff files");
    }

    commonHeader.indexOffset = seqFile.readLong();
    commonHeader.indexLength = seqFile.readInt();
    commonHeader.numReads = seqFile.readInt();
    commonHeader.headerLength = seqFile.readShort();
    commonHeader.keyLength = seqFile.readShort();
    commonHeader.flowLength = seqFile.readShort();
    commonHeader.flowgramFormat = seqFile.readByte();

    byte[] flow = new byte[commonHeader.flowLength];
    super.read(flow);
    commonHeader.flow = new String(flow);

    byte[] key = new byte[commonHeader.keyLength];
    super.read(key);
    commonHeader.key = new String(key);

    int readBytes = COMMON_HEADER_STATIC_SIZE + flow.length + key.length;

    alignToBoundary(readBytes);

    if (super.isSeekable() && commonHeader.indexOffset > commonHeader.headerLength) {
        readIndex();
    }
}

From source file:de.hpi.fgis.hdrs.Triple.java

@Override
public void readFields(DataInput in) throws IOException {
    // read header
    Slen = in.readShort();
    Plen = in.readShort();/*from  ww  w . j ava2 s.  c o m*/
    Olen = in.readInt();
    multiplicity = in.readInt();
    // read data
    //int size = Slen + (int) Plen + Olen;
    int size = bufferSize();
    buffer = new byte[size];
    in.readFully(buffer, 0, size);
}

From source file:dk.statsbiblioteket.util.LineReaderTest.java

public void testSample(String type, DataInput in) throws Exception {
    assertEquals("Int 1 should work for " + type, 12345, in.readInt());
    assertEquals("Int 2 should work for " + type, -87, in.readInt());
    assertEquals("Long should work for " + type, 123456789L, in.readLong());
    assertEquals("String 1 should work for " + type, "Hello World!", in.readLine());
    assertEquals("String 2 should work for " + type, "Another world", in.readLine());
    assertEquals("Float should work for " + type, 0.5f, in.readFloat());
    assertEquals("Boolean 1 should work for " + type, true, in.readBoolean());
    assertEquals("Boolean 2 should work for " + type, false, in.readBoolean());
    assertEquals("Byte 1 should work for " + type, (byte) 12, in.readByte());
    assertEquals("Byte 2 should work for " + type, (byte) -12, in.readByte());
    assertEquals("Unsigned byte should work for " + type, 129, in.readUnsignedByte());
    assertEquals("Short should work for " + type, -4567, in.readShort());
    byte[] loaded = new byte[5];
    byte[] expected = new byte[] { (byte) 'A', (byte) 'S', (byte) 'C', (byte) 'I', (byte) 'I' };
    in.readFully(loaded);//  w  ww  .  j a  v  a2 s .  c o  m
    for (int i = 0; i < loaded.length; i++) {
        assertEquals("Byte-stored string should be equal at byte " + i + " for " + type, expected[i],
                loaded[i]);
    }
}

From source file:org.ambud.marauder.source.ids.pcap.layer3.ARP.java

@Override
public void decode(DataInput di, EtherFrame parent) throws IOException {
    this.parent = parent;
    this.hardType = di.readShort();
    this.protoType = di.readShort();
    this.hardSize = di.readByte();
    this.protoAddrSize = di.readByte();
    this.opCode = di.readShort();
    di.readFully(senderEthAddr);//from   w w w. j a va 2  s.co  m
    this.senderIP = di.readInt();
    di.readFully(targetEthAddr);
    this.targetIP = di.readInt();
}

From source file:org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap.java

/**
 * Read column schema from binary/*from w  ww . j  a  va  2 s  . c o  m*/
 * @param schemaArray
 * @throws IOException
 */
public List<ColumnSchema> readColumnSchema(byte[] schemaArray) throws IOException {
    // uncompress it.
    schemaArray = Snappy.uncompress(schemaArray);
    ByteArrayInputStream schemaStream = new ByteArrayInputStream(schemaArray);
    DataInput schemaInput = new DataInputStream(schemaStream);
    List<ColumnSchema> columnSchemas = new ArrayList<>();
    int size = schemaInput.readShort();
    for (int i = 0; i < size; i++) {
        ColumnSchema columnSchema = new ColumnSchema();
        columnSchema.readFields(schemaInput);
        columnSchemas.add(columnSchema);
    }
    return columnSchemas;
}