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.cloudata.core.commitlog.CommitLogClient.java

static List<TransactionData> readTxDataFrom(String tabletName, DataInputStream dis) throws IOException {
    List<TransactionData> txDataList = new ArrayList<TransactionData>();
    while (true) {
        int totalByteLength = 0;

        try {//from w  w  w.  j  a v  a2  s  .  com
            totalByteLength = dis.readInt();
        } catch (EOFException e) {
            break;
        }

        if (totalByteLength <= 0) {
            LOG.warn("totalByteLength is smaller than zero[" + totalByteLength + "]!!, ignore this data,"
                    + tabletName);
            break;
        }

        if (totalByteLength >= 5 * 1024 * 1024) {
            LOG.warn("totalByteLength is large than 5MB[" + totalByteLength + "]!!, ignore this data,"
                    + tabletName);
            break;
        }
        byte[] bytes = new byte[totalByteLength];
        dis.readFully(bytes);
        txDataList.add(TransactionData.createFrom(bytes));
    }

    return txDataList;
}

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

public static int getMinValue(String filesLocaton) {
    if (null == filesLocaton) {
        return 0;
    }/*from  w  w  w  .  j a va 2 s  .  co m*/
    DataInputStream fileChannel = null;
    try {
        if (!FileFactory.isFileExist(filesLocaton, FileFactory.getFileType(filesLocaton))) {
            return 0;
        }
        fileChannel = new DataInputStream(
                FileFactory.getDataInputStream(filesLocaton, FileFactory.getFileType(filesLocaton), 10240));
        fileChannel.readInt();
        return fileChannel.readInt();
    } catch (IOException e) {
        //            e.printStackTrace();
        LOGGER.error(e, e.getMessage());
    } finally {
        CarbonUtil.closeStreams(fileChannel);
    }
    return 0;
}

From source file:com.android.hierarchyviewerlib.device.DeviceBridge.java

public static PsdFile captureLayers(Window window) {
    DeviceConnection connection = null;/*from   w  ww.  java2  s .  c o  m*/
    DataInputStream in = null;

    try {
        connection = new DeviceConnection(window.getDevice());

        connection.sendCommand("CAPTURE_LAYERS " + window.encode()); //$NON-NLS-1$

        in = new DataInputStream(new BufferedInputStream(connection.getSocket().getInputStream()));

        int width = in.readInt();
        int height = in.readInt();

        PsdFile psd = new PsdFile(width, height);

        while (readLayer(in, psd)) {
        }

        return psd;
    } catch (Exception e) {
        Log.e(TAG, "Unable to capture layers for window " + window.getTitle() + " on device "
                + window.getDevice());
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception ex) {
            }
        }
        connection.close();
    }

    return null;
}

From source file:org.carbondata.processing.dataprocessor.dataretention.CarbonDataRetentionUtil.java

/**
 * This API will scan the level file and return the surrogate key for the
 * valid member//from  ww  w . j a  v a  2  s. c o m
 *
 * @param levelName
 * @throws ParseException
 */
public static Map<Integer, Integer> getSurrogateKeyForRetentionMember(CarbonFile memberFile, String levelName,
        String columnValue, String format, Map<Integer, Integer> mapOfSurrKeyAndAvailStatus) {
    DataInputStream inputStream = null;
    Date storeDateMember = null;
    Date columnValDateMember = null;
    DataInputStream inputStreamForMaxVal = null;
    try {
        columnValDateMember = convertToDateObjectFromStringVal(columnValue, format, true);
    } catch (ParseException e) {
        LOGGER.error(e, "Not able to get surrogate key for value : " + columnValue);
        return mapOfSurrKeyAndAvailStatus;
    }
    try {
        inputStream = FileFactory.getDataInputStream(memberFile.getPath(),
                FileFactory.getFileType(memberFile.getPath()));

        long currPosIndex = 0;
        long size = memberFile.getSize() - 4;
        int minVal = inputStream.readInt();
        int surrogateKeyIndex = minVal;
        currPosIndex += 4;
        //
        int current = 0;
        boolean enableEncoding = Boolean.valueOf(
                CarbonProperties.getInstance().getProperty(CarbonCommonConstants.ENABLE_BASE64_ENCODING,
                        CarbonCommonConstants.ENABLE_BASE64_ENCODING_DEFAULT));
        String memberName = null;
        while (currPosIndex < size) {
            int len = inputStream.readInt();
            currPosIndex += 4;
            byte[] rowBytes = new byte[len];
            inputStream.readFully(rowBytes);
            currPosIndex += len;
            if (enableEncoding) {
                memberName = new String(Base64.decodeBase64(rowBytes), Charset.defaultCharset());
            } else {
                memberName = new String(rowBytes, Charset.defaultCharset());
            }
            int surrogateVal = surrogateKeyIndex + current;
            current++;
            try {
                storeDateMember = convertToDateObjectFromStringVal(memberName, format, false);

            } catch (Exception e) {
                LOGGER.error(e, "Not able to get surrogate key for value : " + memberName);
                continue;
            }
            // means date1 is before date2
            if (null != columnValDateMember && null != storeDateMember) {
                if (storeDateMember.compareTo(columnValDateMember) < 0) {
                    mapOfSurrKeyAndAvailStatus.put(surrogateVal, surrogateVal);
                }
            }

        }

    } catch (IOException e) {
        LOGGER.error(e, "Not able to read level file for Populating Cache : " + memberFile.getName());

    } finally {
        CarbonUtil.closeStreams(inputStream);
        CarbonUtil.closeStreams(inputStreamForMaxVal);

    }

    return mapOfSurrKeyAndAvailStatus;
}

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

public static int getMinValueFromLevelFile(String filesLocaton) {
    if (null == filesLocaton) {
        return 0;
    }/*from   w w w  . ja  v  a2s  .  c  o m*/
    DataInputStream fileChannel = null;
    try {
        if (!FileFactory.isFileExist(filesLocaton, FileFactory.getFileType(filesLocaton))) {
            return 0;
        }
        fileChannel = new DataInputStream(
                FileFactory.getDataInputStream(filesLocaton, FileFactory.getFileType(filesLocaton), 10240));
        return fileChannel.readInt();

    } catch (IOException e) {
        //            e.printStackTrace();
        LOGGER.error(e, e.getMessage());
    } finally {
        CarbonUtil.closeStreams(fileChannel);
    }
    return 0;
}

From source file:org.commoncrawl.service.crawler.CrawlSegmentLog.java

public static int readHeader(DataInputStream reader) throws IOException {
    reader.skipBytes(4);/*  w ww .  j  av a 2 s. co  m*/
    return reader.readInt();
}

From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java

private static QueryScopeInfo deserializeMetricInfo(DataInputStream dis) throws IOException {
    String jobID;/*www .j  av a2s . c  om*/
    String vertexID;
    int subtaskIndex;

    String scope = deserializeString(dis);
    byte cat = dis.readByte();
    switch (cat) {
    case INFO_CATEGORY_JM:
        return new QueryScopeInfo.JobManagerQueryScopeInfo(scope);
    case INFO_CATEGORY_TM:
        String tmID = deserializeString(dis);
        return new QueryScopeInfo.TaskManagerQueryScopeInfo(tmID, scope);
    case INFO_CATEGORY_JOB:
        jobID = deserializeString(dis);
        return new QueryScopeInfo.JobQueryScopeInfo(jobID, scope);
    case INFO_CATEGORY_TASK:
        jobID = deserializeString(dis);
        vertexID = deserializeString(dis);
        subtaskIndex = dis.readInt();
        return new QueryScopeInfo.TaskQueryScopeInfo(jobID, vertexID, subtaskIndex, scope);
    case INFO_CATEGORY_OPERATOR:
        jobID = deserializeString(dis);
        vertexID = deserializeString(dis);
        subtaskIndex = dis.readInt();
        String operatorName = deserializeString(dis);
        return new QueryScopeInfo.OperatorQueryScopeInfo(jobID, vertexID, subtaskIndex, operatorName, scope);
    default:
        throw new IOException("sup");
    }
}

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

public static Map<Integer, Integer> getGlobalSurrogateMappingMapBased(String filesLocaton) {
    if (null == filesLocaton) {
        return null;
    }/*from w ww.  j  a v  a 2s.c  o m*/
    DataInputStream fileChannel = null;
    Map<Integer, Integer> map = new HashMap<Integer, Integer>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    try {
        if (!FileFactory.isFileExist(filesLocaton, FileFactory.getFileType(filesLocaton))) {
            return null;
        }
        fileChannel = FileFactory.getDataInputStream(filesLocaton, FileFactory.getFileType(filesLocaton));
        fileChannel.readInt();
        int numberOfEntries = fileChannel.readInt();
        int counter = 0;
        while (counter < numberOfEntries) {
            map.put(fileChannel.readInt(), fileChannel.readInt());
            counter++;
        }
    } catch (IOException e) {
        //            e.printStackTrace();
        LOGGER.error(e, e.getMessage());
    } finally {
        CarbonUtil.closeStreams(fileChannel);
    }
    return map;
}

From source file:CounterApp.java

public int getCount() throws Exception {
    java.net.URL url = new java.net.URL(servletURL);
    java.net.URLConnection con = url.openConnection();
    if (sessionCookie != null) {
        con.setRequestProperty("cookie", sessionCookie);
    }/*from ww  w  . j  ava  2  s . c  om*/
    con.setUseCaches(false);
    con.setDoOutput(true);
    con.setDoInput(true);
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(byteOut);
    out.flush();
    byte buf[] = byteOut.toByteArray();
    con.setRequestProperty("Content-type", "application/octet-stream");
    con.setRequestProperty("Content-length", "" + buf.length);
    DataOutputStream dataOut = new DataOutputStream(con.getOutputStream());
    dataOut.write(buf);
    dataOut.flush();
    dataOut.close();
    DataInputStream in = new DataInputStream(con.getInputStream());
    int count = in.readInt();
    in.close();
    if (sessionCookie == null) {
        String cookie = con.getHeaderField("set-cookie");
        if (cookie != null) {
            sessionCookie = parseCookie(cookie);
            System.out.println("Setting session ID=" + sessionCookie);
        }
    }

    return count;
}

From source file:additionalpipes.inventory.components.PropertyStrArray.java

@Override
public void readData(DataInputStream data) throws IOException {
    int size = data.readInt();
    if (size > 0) {
        value = new String[size];
        for (int i = 0; i < value.length; i++) {
            value[i] = data.readUTF();/*  w ww.j  a v a 2  s .c  o  m*/
        }
    } else {
        value = ArrayUtils.EMPTY_STRING_ARRAY;
    }
}