Example usage for java.io DataInput readUnsignedShort

List of usage examples for java.io DataInput readUnsignedShort

Introduction

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

Prototype

int readUnsignedShort() throws IOException;

Source Link

Document

Reads two input bytes and returns an int value in the range 0 through 65535 .

Usage

From source file:com.buaa.cfs.io.UTF8.java

/** Skips over one UTF8 in the input. */
public static void skip(DataInput in) throws IOException {
    int length = in.readUnsignedShort();
    WritableUtils.skipFully(in, length);
}

From source file:com.buaa.cfs.io.UTF8.java

/**
 * Read a UTF-8 encoded string.//from  www  . j a  v  a 2 s. c o  m
 *
 * @see DataInput#readUTF()
 */
public static String readString(DataInput in) throws IOException {
    int bytes = in.readUnsignedShort();
    StringBuilder buffer = new StringBuilder(bytes);
    readChars(in, buffer, bytes);
    return buffer.toString();
}

From source file:io.mycat.util.ByteBufferUtil.java

public static int readShortLength(DataInput in) throws IOException {
    return in.readUnsignedShort();
}

From source file:io.UTF8.java

public void readFields(DataInput in) throws IOException {
    length = in.readUnsignedShort();
    if (bytes == null || bytes.length < length)
        bytes = new byte[length];
    in.readFully(bytes, 0, length);/*from  ww  w  . ja v a  2  s.c om*/
}

From source file:com.buaa.cfs.io.UTF8.java

@Override
public void readFields(DataInput in) throws IOException {
    length = in.readUnsignedShort();
    if (bytes == null || bytes.length < length)
        bytes = new byte[length];
    in.readFully(bytes, 0, length);// w  w  w . j  a  va2s . c  om
}

From source file:org.glukit.dexcom.sync.responses.ManufacturingDataDatabasePagesResponse.java

public List<ManufacturingParameters> getManufacturingParameters() {
    List<ManufacturingParameters> manufacturingParameters = newArrayList();
    try {/*  w  w  w  .j ava 2  s. com*/
        for (DatabasePage page : getPages()) {
            ByteArrayInputStream inputStream = new ByteArrayInputStream(page.getPageData());
            DataInput input = this.dataInputFactory.create(inputStream);
            // TODO: something better than ignoring the data?
            long systemSeconds = UnsignedInts.toLong(input.readInt());
            long displaySeconds = UnsignedInts.toLong(input.readInt());

            byte[] xmlBytes = new byte[inputStream.available() - 2];
            input.readFully(xmlBytes);

            validateCrc(input.readUnsignedShort(), page.getPageData());

            XmlMapper xmlMapper = new XmlMapper();
            ManufacturingParameters parameterPage = xmlMapper.readValue(new String(xmlBytes, "UTF-8"),
                    ManufacturingParameters.class);
            manufacturingParameters.add(parameterPage);
        }
        return manufacturingParameters;
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

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

public ReadBlock readReadBlock() throws IOException {
    try {//from w ww . ja  va  2  s  . 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:org.apache.geode.internal.InternalDataSerializer.java

public static int readArrayLength(DataInput in) throws IOException {
    byte code = in.readByte();
    if (code == NULL_ARRAY) {
        return -1;
    } else {//from   w w  w .j  a va  2  s  . co  m
        int result = ubyteToInt(code);
        if (result > MAX_BYTE_ARRAY_LEN) {
            if (code == SHORT_ARRAY_LEN) {
                result = in.readUnsignedShort();
            } else if (code == INT_ARRAY_LEN) {
                result = in.readInt();
            } else {
                throw new IllegalStateException("unexpected array length code=" + code);
            }
        }
        return result;
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

/**
 * Reads an instance of {@code String} from a {@code DataInput} given the header byte already
 * being read. The return value may be {@code null}.
 *
 * @throws IOException A problem occurs while reading from {@code in}
 *
 * @since GemFire 5.7/*from   ww w .j  av  a  2  s .  c  om*/
 */
public static String readString(DataInput in, byte header) throws IOException {
    if (header == DSCODE.STRING_BYTES) {
        int len = in.readUnsignedShort();
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading STRING_BYTES of len={}", len);
        }
        byte[] buf = new byte[len];
        in.readFully(buf, 0, len);
        return new String(buf, 0); // intentionally using deprecated constructor
    } else if (header == DSCODE.STRING) {
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading utf STRING");
        }
        return in.readUTF();
    } else if (header == DSCODE.NULL_STRING) {
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading NULL_STRING");
        }
        return null;
    } else if (header == DSCODE.HUGE_STRING_BYTES) {
        int len = in.readInt();
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading HUGE_STRING_BYTES of len={}", len);
        }
        byte[] buf = new byte[len];
        in.readFully(buf, 0, len);
        return new String(buf, 0); // intentionally using deprecated constructor
    } else if (header == DSCODE.HUGE_STRING) {
        int len = in.readInt();
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading HUGE_STRING of len={}", len);
        }
        char[] buf = new char[len];
        for (int i = 0; i < len; i++) {
            buf[i] = in.readChar();
        }
        return new String(buf);
    } else {
        String s = "Unknown String header " + header;
        throw new IOException(s);
    }
}

From source file:org.apache.hadoop.io.UTF8.java

/** Read a UTF-8 encoded string.
 *
 * @see DataInput#readUTF()/*from  www.  j a v  a  2 s .c  om*/
 */
public static String readString(DataInput in) throws IOException {
    int bytes = in.readUnsignedShort();
    StringBuffer buffer = new StringBuffer(bytes);
    readChars(in, buffer, bytes);
    return buffer.toString();
}