Example usage for java.io DataInputStream readInt

List of usage examples for java.io DataInputStream readInt

Introduction

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

Prototype

public final int readInt() throws IOException 

Source Link

Document

See the general contract of the readInt method of DataInput.

Usage

From source file:org.carbondata.query.util.CacheUtil.java

private static Member[][] populateMemberCache(DataInputStream fileChannel, CarbonFile memberFile,
        String fileName, String dataType) throws IOException {
    // ByteBuffer toltalLength, memberLength, surrogateKey, bf3;
    // subtracted 4 as last 4 bytes will have the max value for no of
    // records/*  www.j a  v a2  s  .  c  om*/
    long currPositionIndex = 0;
    long size = memberFile.getSize() - 4;
    long skipSize = size;
    long actualSkipSize = 0;
    while (actualSkipSize != size) {
        actualSkipSize += fileChannel.skip(skipSize);
        skipSize = skipSize - actualSkipSize;
    }
    //        LOGGER.debug(CarbonEngineLogEvent.UNIBI_CARBONENGINE_MSG, "Bytes skipped " +
    // skipSize);
    int maxVal = fileChannel.readInt();
    CarbonUtil.closeStreams(fileChannel);
    fileChannel = FileFactory.getDataInputStream(fileName, FileFactory.getFileType(fileName));
    // CHECKSTYLE:OFF Approval No:Approval-V1R2C10_005
    ByteBuffer buffer = ByteBuffer.allocate((int) size);
    // CHECKSTYLE:OFF
    fileChannel.readFully(buffer.array());
    int minVal = buffer.getInt();
    int totalArraySize = maxVal - minVal + 1;
    Member[][] surogateKeyArrays = null;
    if (totalArraySize > CarbonCommonConstants.LEVEL_ARRAY_SIZE) {
        int div = totalArraySize / CarbonCommonConstants.LEVEL_ARRAY_SIZE;
        int rem = totalArraySize % CarbonCommonConstants.LEVEL_ARRAY_SIZE;
        if (rem > 0) {
            div++;
        }
        surogateKeyArrays = new Member[div][];

        for (int i = 0; i < div - 1; i++) {
            surogateKeyArrays[i] = new Member[CarbonCommonConstants.LEVEL_ARRAY_SIZE];
        }

        if (rem > 0) {
            surogateKeyArrays[surogateKeyArrays.length - 1] = new Member[rem];
        } else {
            surogateKeyArrays[surogateKeyArrays.length
                    - 1] = new Member[CarbonCommonConstants.LEVEL_ARRAY_SIZE];
        }
    } else {
        surogateKeyArrays = new Member[1][totalArraySize];
    }
    //        Member[] surogateKeyArrays = new Member[maxVal-minVal+1];
    //        int surrogateKeyIndex = minVal;
    currPositionIndex += 4;
    //
    int current = 0;
    // CHECKSTYLE:OFF Approval No:Approval-V1R2C10_005
    boolean enableEncoding = Boolean
            .valueOf(CarbonProperties.getInstance().getProperty(CarbonCommonConstants.ENABLE_BASE64_ENCODING,
                    CarbonCommonConstants.ENABLE_BASE64_ENCODING_DEFAULT));
    // CHECKSTYLE:ON
    int index = 0;
    int prvArrayIndex = 0;
    while (currPositionIndex < size) {
        int len = buffer.getInt();
        // CHECKSTYLE:OFF Approval No:Approval-V1R2C10_005
        // CHECKSTYLE:ON
        currPositionIndex += 4;
        byte[] rowBytes = new byte[len];
        buffer.get(rowBytes);
        currPositionIndex += len;
        // No:Approval-361
        if (enableEncoding) {
            rowBytes = Base64.decodeBase64(rowBytes);
        }
        surogateKeyArrays[current / CarbonCommonConstants.LEVEL_ARRAY_SIZE][index] = new Member(rowBytes);
        current++;
        if (current / CarbonCommonConstants.LEVEL_ARRAY_SIZE > prvArrayIndex) {
            prvArrayIndex++;
            index = 0;
        } else {
            index++;
        }
    }
    return surogateKeyArrays;
}

From source file:org.xenei.bloomgraph.SerializableNode.java

/**
 * Read a string from the input stream./*from  w w w .  j av a  2  s . com*/
 * 
 * @see write()
 * @param is
 *            the input stream
 * @return the string read from the stream.
 * @throws IOException
 */
private String read(DataInputStream is) throws IOException {
    int n = is.readInt();
    if (n == -1) {
        return null;
    }
    byte[] b = new byte[n];
    if (n > 0) {
        is.read(b);
    }
    return decodeString(b);
}

From source file:org.hyperic.hq.measurement.agent.server.MeasurementSchedule.java

private void populateSRNInfo() {
    srnList.clear();//  w w w.j ava  2 s  .  c o m
    final String lengthBuf = store.getValue(PROP_MSRNS_LENGTH);
    final List<Byte> encSRNBytes = new ArrayList<Byte>();
    if (lengthBuf == null) {
        final String mSchedBuf = store.getValue(PROP_MSRNS);
        if (mSchedBuf == null) {
            log.warn("no srns to retrieve from storage");
            return;
        }
        final byte[] bytes = Base64.decode(mSchedBuf);
        encSRNBytes.addAll(Arrays.asList(ArrayUtils.toObject(bytes)));
    } else {
        final int length = Integer.parseInt(lengthBuf);
        for (int i = 0; i < length; i++) {
            final byte[] bytes = Base64.decode(store.getValue(PROP_MSRNS + "_" + i));
            encSRNBytes.addAll(Arrays.asList(ArrayUtils.toObject(bytes)));
        }
    }
    byte[] srnBytes = ArrayUtils.toPrimitive(encSRNBytes.toArray(new Byte[0]));
    HashSet<AppdefEntityID> seenEnts = new HashSet<AppdefEntityID>();
    String srnBuf = new String(srnBytes);
    ByteArrayInputStream bIs = new ByteArrayInputStream(srnBytes);
    DataInputStream dIs = new DataInputStream(bIs);
    try {
        int numSRNs = dIs.readInt();
        int entType, entID, revNo;

        for (int i = 0; i < numSRNs; i++) {
            entType = dIs.readInt();
            entID = dIs.readInt();
            revNo = dIs.readInt();
            AppdefEntityID ent = new AppdefEntityID(entType, entID);
            if (seenEnts.contains(ent)) {
                log.warn("Entity '" + ent + "' contained more than once in SRN storage.  Ignoring");
                continue;
            }
            seenEnts.add(ent);
            srnList.add(new SRN(ent, revNo));
        }
    } catch (IOException exc) {
        this.log.error("Unable to decode SRN list: " + exc + " srn=\"" + srnBuf + "\"", exc);
    }
}

From source file:org.godhuli.rhipe.RHMR.java

public void readParametersFromR(String configfile) throws IOException {
    FileInputStream in = new FileInputStream(configfile);
    DataInputStream fin = new DataInputStream(in);
    byte[] d;/*from www .  jav  a  2  s  .c  om*/
    String key, value;
    int n0 = fin.readInt(), n;
    for (int i = 0; i < n0; i++) {
        // R Writes Null Terminated Strings(when I dont use char2Raw)
        try {
            n = fin.readInt();
            d = new byte[n];
            fin.readFully(d, 0, d.length);
            key = new String(d);

            n = fin.readInt();
            d = new byte[n];
            fin.readFully(d, 0, d.length);
            value = new String(d);
            rhoptions_.put(key, value);
        } catch (EOFException e) {
            throw new IOException(e);
        }
    }
    fin.close();
    if (debug_) {
        Enumeration keys = rhoptions_.keys();
        while (keys.hasMoreElements()) {
            String key0 = (String) keys.nextElement();
            String value0 = (String) rhoptions_.get(key0);
            System.out.println(key0 + "=" + value0);
        }
    }
}

From source file:com.opensoc.json.serialization.JSONKafkaSerializer.java

@SuppressWarnings("unchecked")
public JSONObject fromBytes1(DataInputStream data) {

    //ByteArrayInputStream inputBuffer = new ByteArrayInputStream(input);
    //DataInputStream data = new DataInputStream(inputBuffer);

    JSONObject output = new JSONObject();

    try {/* w w w.j  a v a  2s . c o m*/
        int mapSize = data.readInt();

        for (int i = 0; i < mapSize; i++) {
            String key = (String) getObject(data);
            // System.out.println("Key Found"+ key);
            Object val = getObject(data);
            output.put(key, val);
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }

    return output;
}

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

/**
 * Loads the packet from the given input stream.
 * // ww  w .java2 s  .  co  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);
}

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  ww  .j  a  v  a  2s  . c om
        throw new IOException("Unexpected stream version: " + v);

    return din.readInt();
}

From source file:com.linkedin.pinot.index.writer.FixedByteWidthRowColDataFileWriterTest.java

@Test
public void testMultiCol() throws Exception {

    File file = new File("test_single_col_writer.dat");
    file.delete();//from   w w w.j  a va 2s .  com
    int rows = 100;
    int cols = 2;
    int[] columnSizes = new int[] { 4, 4 };
    FixedByteSingleValueMultiColWriter writer = new FixedByteSingleValueMultiColWriter(file, rows, cols,
            columnSizes);
    int[][] data = new int[rows][cols];
    Random r = new Random();
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            data[i][j] = r.nextInt();
            writer.setInt(i, j, data[i][j]);
        }
    }
    writer.close();
    DataInputStream dis = new DataInputStream(new FileInputStream(file));
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            Assert.assertEquals(dis.readInt(), data[i][j]);
        }
    }
    dis.close();
    file.delete();
}

From source file:org.hyperic.hq.agent.client.AgentConnection.java

/**
 * Get the result of command execution from the remote command handler.
 *
 * @param inStreamPair The pair which was returned from the associated
 *                     sendCommandHeaders invocation.
 *
 * @return an AgentRemoteValue object, as returned from the Agent.
 *
 * @throws AgentRemoteException indicating an error invoking the method.
 * @throws AgentConnectionException indicating a failure to communicate
 *                                  with the agent.
 *//*from w  w  w. j a  va 2s .com*/

public AgentRemoteValue getCommandResult(AgentStreamPair inStreamPair)
        throws AgentRemoteException, AgentConnectionException {
    SocketStreamPair streamPair = (SocketStreamPair) inStreamPair;
    // Get the response
    try {
        DataInputStream inputStream;
        int isException;

        inputStream = new DataInputStream(streamPair.getInputStream());
        isException = inputStream.readInt();
        if (isException == 1) {
            String exceptionMsg = inputStream.readUTF();

            throw new AgentRemoteException(exceptionMsg);
        } else {
            AgentRemoteValue result;

            result = AgentRemoteValue.fromStream(inputStream);
            return result;
        }
    } catch (EOFException exc) {
        throw new AgentConnectionException("EOF received from Agent");
    } catch (IOException exc) {
        throw new AgentConnectionException("Error reading result: " + exc.getMessage(), exc);
    } finally {
        close(streamPair);
    }
}