Example usage for java.io DataInputStream readShort

List of usage examples for java.io DataInputStream readShort

Introduction

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

Prototype

public final short readShort() throws IOException 

Source Link

Document

See the general contract of the readShort method of DataInput.

Usage

From source file:ubic.gemma.analysis.preprocess.batcheffects.AffyScanDateExtractor.java

private int readShortLittleEndian(DataInputStream dis) throws IOException {
    return dis.readShort();
}

From source file:org.apache.hadoop.dfs.TestBlockReplacement.java

private boolean replaceBlock(Block block, DatanodeInfo source, DatanodeInfo sourceProxy,
        DatanodeInfo destination) throws IOException {
    Socket sock = new Socket();
    sock.connect(NetUtils.createSocketAddr(sourceProxy.getName()), FSConstants.READ_TIMEOUT);
    sock.setKeepAlive(true);//  w  w  w .j  av a  2  s.  c  o m
    // sendRequest
    DataOutputStream out = new DataOutputStream(sock.getOutputStream());
    out.writeShort(FSConstants.DATA_TRANSFER_VERSION);
    out.writeByte(FSConstants.OP_COPY_BLOCK);
    out.writeLong(block.getBlockId());
    out.writeLong(block.getGenerationStamp());
    Text.writeString(out, source.getStorageID());
    destination.write(out);
    out.flush();
    // receiveResponse
    DataInputStream reply = new DataInputStream(sock.getInputStream());

    short status = reply.readShort();
    if (status == FSConstants.OP_STATUS_SUCCESS) {
        return true;
    }
    return false;
}

From source file:org.apache.hadoop.hdfs.server.datanode.TestBlockReplacement.java

private boolean replaceBlock(Block block, DatanodeInfo source, DatanodeInfo sourceProxy,
        DatanodeInfo destination) throws IOException {
    Socket sock = new Socket();
    sock.connect(NetUtils.createSocketAddr(destination.getName()), HdfsConstants.READ_TIMEOUT);
    sock.setKeepAlive(true);//w  w w  .  j  a v  a 2s . co  m
    // sendRequest
    DataOutputStream out = new DataOutputStream(sock.getOutputStream());
    out.writeShort(DataTransferProtocol.DATA_TRANSFER_VERSION);
    out.writeByte(DataTransferProtocol.OP_REPLACE_BLOCK);
    out.writeLong(block.getBlockId());
    out.writeLong(block.getGenerationStamp());
    Text.writeString(out, source.getStorageID());
    sourceProxy.write(out);
    BlockTokenSecretManager.DUMMY_TOKEN.write(out);
    out.flush();
    // receiveResponse
    DataInputStream reply = new DataInputStream(sock.getInputStream());

    short status = reply.readShort();
    if (status == DataTransferProtocol.OP_STATUS_SUCCESS) {
        return true;
    }
    return false;
}

From source file:org.structr.core.graph.SyncCommand.java

private static Object readObject(final DataInputStream inputStream, final byte type) throws IOException {

    switch (type) {

    case 0://w w  w .  j  a  v  a2 s .  co m
    case 1:
        return inputStream.readByte();

    case 2:
    case 3:
        return inputStream.readShort();

    case 4:
    case 5:
        return inputStream.readInt();

    case 6:
    case 7:
        return inputStream.readLong();

    case 8:
    case 9:
        return inputStream.readFloat();

    case 10:
    case 11:
        return inputStream.readDouble();

    case 12:
    case 13:
        return inputStream.readChar();

    case 14:
    case 15:
        return new String(deserializeData(inputStream), "UTF-8");

    // this doesn't work with very long strings
    //return inputStream.readUTF();

    case 16:
    case 17:
        return inputStream.readBoolean();
    }

    return null;
}

From source file:SafeUTF.java

public String safeReadUTF(DataInputStream in) throws IOException {
    boolean isNull = in.readByte() == NULL;

    if (isNull) {
        return null;
    }//from  w w w  . ja v a  2  s  .c  om

    short numChunks = in.readShort();

    int bufferSize = chunkSize * numChunks;

    // special handling for single chunk
    if (numChunks == 1) {
        // The text size is likely to be much smaller than the chunkSize
        // so set bufferSize to the min of the input stream available
        // and the maximum buffer size. Since the input stream
        // available() can be <= 0 we check for that and default to
        // a small msg size of 256 bytes.

        int inSize = in.available();

        if (inSize <= 0) {
            inSize = 256;
        }

        bufferSize = Math.min(inSize, bufferSize);

        lastReadBufferSize = bufferSize;
    }

    StringBuffer buff = new StringBuffer(bufferSize);

    for (int i = 0; i < numChunks; i++) {
        String s = in.readUTF();

        buff.append(s);
    }

    return buff.toString();
}

From source file:org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverReader.java

private int parseHeader(DataInputStream din) throws IOException {
    if (din.readLong() != RiverWriter.HEADER)
        throw new IOException("Invalid stream header");

    short v = din.readShort();
    if (v != 1)//from w  w  w. j a va2s.  c o m
        throw new IOException("Unexpected stream version: " + v);

    return din.readInt();
}

From source file:com.github.terma.m.server.Repo.java

public Map<String, Short> readMetricCodes() throws IOException {
    Map<String, Short> result = new HashMap<>();
    DataInputStream ois = null;
    try {//www  .  j  a v a 2s .co  m
        ois = new DataInputStream(new FileInputStream(eventCodesFile));
        //noinspection InfiniteLoopStatement
        while (true) {
            result.put(ois.readUTF(), ois.readShort());
        }
    } catch (EOFException | FileNotFoundException e) {
        // just end
    } finally {
        IOUtils.closeQuietly(ois);
    }
    return result;
}

From source file:ubic.gemma.core.analysis.preprocess.batcheffects.AffyScanDateExtractor.java

private int readShort(DataInputStream dis) throws IOException {
    return dis.readShort();
}

From source file:com.igormaznitsa.jhexed.swing.editor.filecontainer.FileContainer.java

private List<FileContainerSection> loadFromStream(final InputStream in) throws IOException {
    final DataInputStream din = in instanceof DataInputStream ? (DataInputStream) in : new DataInputStream(in);

    if (din.readInt() != MAGIC) {
        throw new IOException("Wrong format, can't find magic");
    }/*from   w  w w.  j  a  v a 2s. c o m*/

    final int version = din.readShort() & 0xFFFF;

    if (version > FORMAT_VERSION) {
        throw new IllegalArgumentException("Detected unsupported version [" + version + ']');
    }

    final int sectionNumber = din.readUnsignedShort();

    final List<FileContainerSection> result = new ArrayList<FileContainerSection>(Math.max(5, sectionNumber));

    for (int i = 0; i < sectionNumber; i++) {
        final FileContainerSection s = new FileContainerSection(in);
        result.add(s);
    }
    if (din.readInt() != MAGIC) {
        throw new IOException("Can't detecte the end MAGIC");
    }

    return result;
}

From source file:it.jnrpe.net.JNRPEProtocolPacket.java

/**
 * Loads the packet from the given input stream.
 * /*from w  ww. j  a  va 2 s  . c  o m*/
 * @param in the packet input stream
        
 * @throws IOException on any error */
protected void fromInputStream(final InputStream in) throws IOException {
    DataInputStream din = new DataInputStream(in);
    packetVersion = din.readShort();
    packetTypeCode = din.readShort();
    crcValue = din.readInt();
    resultCode = din.readShort();
    din.readFully(byteBufferAry);
    din.readFully(dummyBytesAry);
}