Example usage for java.io DataInput readLong

List of usage examples for java.io DataInput readLong

Introduction

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

Prototype

long readLong() throws IOException;

Source Link

Document

Reads eight input bytes and returns a long value.

Usage

From source file:org.apache.hadoop.mapred.ClusterStatus.java

public void readFields(DataInput in) throws IOException {
    numActiveTrackers = in.readInt();/*w w w  .j  a va2s.com*/
    int numTrackerNames = in.readInt();
    if (numTrackerNames > 0) {
        for (int i = 0; i < numTrackerNames; i++) {
            String name = Text.readString(in);
            activeTrackers.add(name);
        }
    }
    numBlacklistedTrackers = in.readInt();
    numTrackerNames = in.readInt();
    if (numTrackerNames > 0) {
        for (int i = 0; i < numTrackerNames; i++) {
            String name = Text.readString(in);
            blacklistedTrackers.add(name);
        }
    }
    numGraylistedTrackers = in.readInt();
    numTrackerNames = in.readInt();
    if (numTrackerNames > 0) {
        for (int i = 0; i < numTrackerNames; i++) {
            String name = Text.readString(in);
            graylistedTrackers.add(name);
        }
    }
    numExcludedNodes = in.readInt();
    ttExpiryInterval = in.readLong();
    map_tasks = in.readInt();
    reduce_tasks = in.readInt();
    max_map_tasks = in.readInt();
    max_reduce_tasks = in.readInt();
    used_memory = in.readLong();
    max_memory = in.readLong();
    state = WritableUtils.readEnum(in, JobTracker.State.class);
}

From source file:org.apache.hadoop.mapred.SampleTaskStatus.java

public void readFields(DataInput in) throws IOException {

    this.sampleMapTaskId.readFields(in);
    sampleMapTracker = in.readUTF();//  w  w  w  . java  2  s .c  om
    readInputStartTime = in.readLong();
    readInputDoneTime = in.readLong();
    writeOutputStartTime = in.readLong();
    writeOutputDoneTime = in.readLong();
    networkSampleMapCopyDurationMilliSec = in.readLong();
    additionalSpillDurationMilliSec = in.readLong();
    additionalSpillSize = in.readLong();
}

From source file:org.apache.hadoop.mapred.SortedRanges.java

public synchronized void readFields(DataInput in) throws IOException {
    indicesCount = in.readLong();
    ranges = new TreeSet<Range>();
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        Range range = new Range();
        range.readFields(in);/* www  .ja va2 s  .  c  o  m*/
        ranges.add(range);
    }
}

From source file:org.apache.hadoop.mapred.TaskStatus.java

public void readFields(DataInput in) throws IOException {
    this.taskid.readFields(in);
    this.progress = in.readFloat();
    this.numSlots = in.readInt();
    this.runState = WritableUtils.readEnum(in, State.class);
    this.diagnosticInfo = Text.readString(in);
    this.stateString = Text.readString(in);
    this.phase = WritableUtils.readEnum(in, Phase.class);
    this.startTime = in.readLong();
    this.finishTime = in.readLong();
    counters = new Counters();
    this.includeCounters = in.readBoolean();
    this.outputSize = in.readLong();
    if (includeCounters) {
        counters.readFields(in);/*from   w  w w.  j av  a  2  s . co m*/
    }
    nextRecordRange.readFields(in);
}

From source file:org.apache.hadoop.vertica.VerticaInputSplit.java

/** {@inheritDoc} */
public void readFields(DataInput in) throws IOException {
    inputQuery = Text.readString(in);
    long paramCount = in.readLong();
    if (paramCount > 0) {
        VerticaRecord record = new VerticaRecord();
        record.readFields(in);/*from w ww  .j  a va2 s .  c o m*/
        segmentParams = record.getValues();
    }
    start = in.readLong();
    end = in.readLong();
}

From source file:org.apache.hama.bsp.Directive.java

public void readFields(DataInput in) throws IOException {
    this.timestamp = in.readLong();
    int t = in.readInt();
    if (Directive.Type.Request.value() == t) {
        this.type = Directive.Type.Request;
        int length = WritableUtils.readVInt(in);
        if (length > 0) {
            this.actionList = new ArrayList<GroomServerAction>();
            for (int i = 0; i < length; ++i) {
                GroomServerAction.ActionType actionType = WritableUtils.readEnum(in,
                        GroomServerAction.ActionType.class);
                GroomServerAction action = GroomServerAction.createAction(actionType);
                action.readFields(in);/* w  ww  .j a  va 2s. c o  m*/
                actionList.add(action);
            }
        } else {
            this.actionList = null;
        }
        String[] groomServerNames = WritableUtils.readCompressedStringArray(in);
        String[] groomServerAddresses = WritableUtils.readCompressedStringArray(in);
        groomServerPeers = new HashMap<String, String>(groomServerNames.length);

        for (int i = 0; i < groomServerNames.length; i++) {
            groomServerPeers.put(groomServerNames[i], groomServerAddresses[i]);
        }
    } else if (Directive.Type.Response.value() == t) {
        this.type = Directive.Type.Response;
        this.status = new GroomServerStatus();
        this.status.readFields(in);
    } else {
        throw new IllegalStateException("Wrong directive type:" + t);
    }
}

From source file:org.apache.hama.bsp.JobStatus.java

@Override
public synchronized void readFields(DataInput in) throws IOException {
    this.jobid = new BSPJobID();
    jobid.readFields(in);//  w w  w  . j ava2  s  . c o m
    this.setupProgress = in.readLong();
    this.progress = in.readLong();
    this.cleanupProgress = in.readLong();
    this.runState = in.readInt();
    this.startTime = in.readLong();
    this.finishTime = in.readLong();
    this.user = Text.readString(in);
    this.schedulingInfo = Text.readString(in);
    this.superstepCount = in.readLong();
    counter = new Counters();
    counter.readFields(in);
}

From source file:org.apache.hama.bsp.TaskStatus.java

@Override
public void readFields(DataInput in) throws IOException {
    this.jobId.readFields(in);
    this.taskId.readFields(in);
    this.progress = in.readFloat();
    this.runState = WritableUtils.readEnum(in, State.class);
    this.stateString = Text.readString(in);
    this.phase = WritableUtils.readEnum(in, Phase.class);
    this.startTime = in.readLong();
    this.finishTime = in.readLong();

    counters = new Counters();
    this.counters.readFields(in);
}

From source file:org.apache.hawq.pxf.service.io.GPDBWritable.java

@Override
public void readFields(DataInput in) throws IOException {
    /*//from www .  java  2  s.  c o m
     * extract pkt len.
    *
    * GPSQL-1107:
    * The DataInput might already be empty (EOF), but we can't check it beforehand.
    * If that's the case, pktlen is updated to -1, to mark that the object is still empty.
    * (can be checked with isEmpty()).
    */
    pktlen = readPktLen(in);
    if (isEmpty()) {
        return;
    }

    /* extract the version and col cnt */
    int version = in.readShort();
    int curOffset = 4 + 2;
    int colCnt;

    /* !!! Check VERSION !!! */
    if (version != GPDBWritable.VERSION && version != GPDBWritable.PREV_VERSION) {
        throw new IOException("Current GPDBWritable version(" + GPDBWritable.VERSION
                + ") does not match input version(" + version + ")");
    }

    if (version == GPDBWritable.VERSION) {
        errorFlag = in.readByte();
        curOffset += 1;
    }

    colCnt = in.readShort();
    curOffset += 2;

    /* Extract Column Type */
    colType = new int[colCnt];
    DBType[] coldbtype = new DBType[colCnt];
    for (int i = 0; i < colCnt; i++) {
        int enumType = (in.readByte());
        curOffset += 1;
        if (enumType == DBType.BIGINT.ordinal()) {
            colType[i] = BIGINT.getOID();
            coldbtype[i] = DBType.BIGINT;
        } else if (enumType == DBType.BOOLEAN.ordinal()) {
            colType[i] = BOOLEAN.getOID();
            coldbtype[i] = DBType.BOOLEAN;
        } else if (enumType == DBType.FLOAT8.ordinal()) {
            colType[i] = FLOAT8.getOID();
            coldbtype[i] = DBType.FLOAT8;
        } else if (enumType == DBType.INTEGER.ordinal()) {
            colType[i] = INTEGER.getOID();
            coldbtype[i] = DBType.INTEGER;
        } else if (enumType == DBType.REAL.ordinal()) {
            colType[i] = REAL.getOID();
            coldbtype[i] = DBType.REAL;
        } else if (enumType == DBType.SMALLINT.ordinal()) {
            colType[i] = SMALLINT.getOID();
            coldbtype[i] = DBType.SMALLINT;
        } else if (enumType == DBType.BYTEA.ordinal()) {
            colType[i] = BYTEA.getOID();
            coldbtype[i] = DBType.BYTEA;
        } else if (enumType == DBType.TEXT.ordinal()) {
            colType[i] = TEXT.getOID();
            coldbtype[i] = DBType.TEXT;
        } else {
            throw new IOException("Unknown GPDBWritable.DBType ordinal value");
        }
    }

    /* Extract null bit array */
    byte[] nullbytes = new byte[getNullByteArraySize(colCnt)];
    in.readFully(nullbytes);
    curOffset += nullbytes.length;
    boolean[] colIsNull = byteArrayToBooleanArray(nullbytes, colCnt);

    /* extract column value */
    colValue = new Object[colCnt];
    for (int i = 0; i < colCnt; i++) {
        if (!colIsNull[i]) {
            /* Skip the alignment padding */
            int skipbytes = roundUpAlignment(curOffset, coldbtype[i].getAlignment()) - curOffset;
            for (int j = 0; j < skipbytes; j++) {
                in.readByte();
            }
            curOffset += skipbytes;

            /* For fixed length type, increment the offset according to type type length here.
                 * For var length type (BYTEA, TEXT), we'll read 4 byte length header and the
             * actual payload.
             */
            int varcollen = -1;
            if (coldbtype[i].isVarLength()) {
                varcollen = in.readInt();
                curOffset += 4 + varcollen;
            } else {
                curOffset += coldbtype[i].getTypeLength();
            }

            switch (DataType.get(colType[i])) {
            case BIGINT: {
                colValue[i] = in.readLong();
                break;
            }
            case BOOLEAN: {
                colValue[i] = in.readBoolean();
                break;
            }
            case FLOAT8: {
                colValue[i] = in.readDouble();
                break;
            }
            case INTEGER: {
                colValue[i] = in.readInt();
                break;
            }
            case REAL: {
                colValue[i] = in.readFloat();
                break;
            }
            case SMALLINT: {
                colValue[i] = in.readShort();
                break;
            }

            /* For BYTEA column, it has a 4 byte var length header. */
            case BYTEA: {
                colValue[i] = new byte[varcollen];
                in.readFully((byte[]) colValue[i]);
                break;
            }
            /* For text formatted column, it has a 4 byte var length header
             * and it's always null terminated string.
            * So, we can remove the last "\0" when constructing the string.
            */
            case TEXT: {
                byte[] data = new byte[varcollen];
                in.readFully(data, 0, varcollen);
                colValue[i] = new String(data, 0, varcollen - 1, CHARSET);
                break;
            }

            default:
                throw new IOException("Unknown GPDBWritable ColType");
            }
        }
    }

    /* Skip the ending alignment padding */
    int skipbytes = roundUpAlignment(curOffset, 8) - curOffset;
    for (int j = 0; j < skipbytes; j++) {
        in.readByte();
    }
    curOffset += skipbytes;

    if (errorFlag != 0) {
        throw new IOException("Received error value " + errorFlag + " from format");
    }
}

From source file:org.apache.isis.objectstore.nosql.db.file.server.FileServer.java

private void startSyncing() {
    final String syncHost = config.getString("fileserver.sync-host", DEFAULT_HOST);
    final int syncPort = config.getInt("fileserver.sync-port", DEFAULT_SYNC_PORT);
    final int connectionTimeout = config.getInt("fileserver.connection.timeout", 5000);

    LOG.info("preparing to sync to secondary server on " + syncHost + " port " + syncPort);

    final InetAddress address;
    try {//  w  w w.j  a v  a2 s .com
        address = InetAddress.getByName(syncHost);
    } catch (final UnknownHostException e) {
        LOG.error("Unknown host " + syncHost, e);
        System.exit(0);
        return;
    }

    while (awaitConnections) {
        Socket socket = null;
        try {
            socket = new Socket(address, syncPort);
            LOG.info("sync connected to " + socket.getInetAddress().getHostAddress() + " port "
                    + socket.getLocalPort());

            final CRC32 crc32 = new CRC32();
            final DataOutput output = new DataOutputStream(
                    new CheckedOutputStream(socket.getOutputStream(), crc32));
            final DataInput input = new DataInputStream(socket.getInputStream());
            output.writeByte(INIT);
            long logId = input.readLong();
            do {
                final long nextLogId = logId + 1;
                final File file = Util.logFile(nextLogId);
                if (file.exists() && server.getLogger().isWritten(nextLogId)) {
                    logId++;

                    output.writeByte(RECOVERY_LOG);
                    crc32.reset();
                    output.writeLong(logId);

                    LOG.info("sending recovery file: " + file.getName());
                    final BufferedInputStream fileInput = new BufferedInputStream(new FileInputStream(file));

                    final byte[] buffer = new byte[8092];
                    int read;
                    while ((read = fileInput.read(buffer)) > 0) {
                        output.writeInt(read);
                        output.write(buffer, 0, read);
                    }
                    output.writeInt(0);

                    output.writeLong(crc32.getValue());
                }
                try {
                    Thread.sleep(300);
                } catch (final InterruptedException ignore) {
                }

                while (isQuiescent) {
                    try {
                        Thread.sleep(300);
                    } catch (final InterruptedException ignore) {
                    }
                }
            } while (awaitConnections);

        } catch (final ConnectException e) {
            LOG.warn("not yet connected to secondary server at " + syncHost + " port " + syncPort);
            try {
                Thread.sleep(connectionTimeout);
            } catch (final InterruptedException ignore) {
            }
        } catch (final IOException e) {
            LOG.error("start failure - networking not set up for " + syncHost, e);
            try {
                Thread.sleep(300);
            } catch (final InterruptedException ignore) {
            }
        } catch (final RuntimeException e) {
            LOG.error("start failure", e);
            try {
                Thread.sleep(300);
            } catch (final InterruptedException ignore) {
            }
        }
    }

}