Example usage for java.io DataInput readFully

List of usage examples for java.io DataInput readFully

Introduction

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

Prototype

void readFully(byte b[], int off, int len) throws IOException;

Source Link

Document

Reads len bytes from an input stream.

Usage

From source file:org.apache.hadoop.hive.accumulo.AccumuloHiveRow.java

@Override
public void readFields(DataInput dataInput) throws IOException {
    if (dataInput.readBoolean()) {
        rowId = dataInput.readUTF();/*from   www  .ja  v  a  2 s.co m*/
    }
    int size = dataInput.readInt();
    for (int i = 0; i < size; i++) {
        int cfLength = dataInput.readInt();
        byte[] cfData = new byte[cfLength];
        dataInput.readFully(cfData, 0, cfLength);
        Text cf = new Text(cfData);
        int cqLength = dataInput.readInt();
        byte[] cqData = new byte[cqLength];
        dataInput.readFully(cqData, 0, cqLength);
        Text cq = new Text(cqData);
        int valSize = dataInput.readInt();
        byte[] val = new byte[valSize];
        for (int j = 0; j < valSize; j++) {
            val[j] = dataInput.readByte();
        }
        tuples.add(new ColumnTuple(cf, cq, val));
    }
}

From source file:org.apache.hadoop.hive.ql.io.orc.OrcSplit.java

@Override
public void readFields(DataInput in) throws IOException {
    //deserialize path, offset, length using FileSplit
    super.readFields(in);

    byte flags = in.readByte();
    hasFooter = (FOOTER_FLAG & flags) != 0;
    isOriginal = (ORIGINAL_FLAG & flags) != 0;
    hasBase = (BASE_FLAG & flags) != 0;
    boolean hasFileId = (HAS_FILEID_FLAG & flags) != 0;

    deltas.clear();/*from   w w w. jav  a 2 s.com*/
    int numDeltas = in.readInt();
    for (int i = 0; i < numDeltas; i++) {
        AcidInputFormat.DeltaMetaData dmd = new AcidInputFormat.DeltaMetaData();
        dmd.readFields(in);
        deltas.add(dmd);
    }
    if (hasFooter) {
        // deserialize FileMetaInfo fields
        String compressionType = Text.readString(in);
        int bufferSize = WritableUtils.readVInt(in);
        int metadataSize = WritableUtils.readVInt(in);

        // deserialize FileMetaInfo field footer
        int footerBuffSize = WritableUtils.readVInt(in);
        ByteBuffer footerBuff = ByteBuffer.allocate(footerBuffSize);
        in.readFully(footerBuff.array(), 0, footerBuffSize);
        OrcFile.WriterVersion writerVersion = ReaderImpl.getWriterVersion(WritableUtils.readVInt(in));

        fileMetaInfo = new ReaderImpl.FileMetaInfo(compressionType, bufferSize, metadataSize, footerBuff,
                writerVersion);
    }
    if (hasFileId) {
        fileId = in.readLong();
    }
}

From source file:org.apache.hadoop.hive.serde2.io.TimestampWritable.java

public void readFields(DataInput in) throws IOException {
    in.readFully(internalBytes, 0, 4);
    if (TimestampWritable.hasDecimal(internalBytes[0])) {
        in.readFully(internalBytes, 4, 1);
        int len = (byte) WritableUtils.decodeVIntSize(internalBytes[4]);
        in.readFully(internalBytes, 5, len - 1);
    }/* w w  w  .  j a  va 2  s . c om*/
    currentBytes = internalBytes;
    this.offset = 0;
}

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

public void readFields(DataInput in) throws IOException {
    setSize(0); // clear the old data
    setSize(in.readInt());//from  ww w .j a  v a2s .co m
    in.readFully(bytes, 0, size);
}

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

private void syncConnection(final Socket connection, final int readTimeout) {
    try {//from  w  w  w.  j a va 2s.  c  o m
        final CRC32 crc32 = new CRC32();
        final DataOutput output = new DataOutputStream(connection.getOutputStream());
        final DataInput input = new DataInputStream(new CheckedInputStream(connection.getInputStream(), crc32));

        if (input.readByte() != INIT) {
            return;
        }

        final LogRange logFileRange = Util.logFileRange();
        final long lastId = logFileRange.noLogFile() ? -1 : logFileRange.getLast();
        output.writeLong(lastId);
        do {
            if (input.readByte() != RECOVERY_LOG) {
                return;
            }
            crc32.reset();
            final long logId = input.readLong();
            final File file = Util.tmpLogFile(logId);
            LOG.info("syncing recovery file: " + file.getName());
            final BufferedOutputStream fileOutput = new BufferedOutputStream(new FileOutputStream(file));

            final byte[] buffer = new byte[8092];
            int length;
            while ((length = input.readInt()) > 0) {
                input.readFully(buffer, 0, length);
                fileOutput.write(buffer, 0, length);
            }
            fileOutput.close();

            final long calculatedChecksum = crc32.getValue();
            final long sentChecksum = input.readLong();
            if (calculatedChecksum != sentChecksum) {
                throw new NoSqlStoreException("Checksum didn't match during download of " + file.getName());
            }

            recover(file);
            final File renameTo = Util.logFile(logId);
            file.renameTo(renameTo);
        } while (true);
    } catch (final NoSqlStoreException e) {
        LOG.error("file server failure", e);
    } catch (final IOException e) {
        LOG.error("networking failure", e);
    } catch (final RuntimeException e) {
        LOG.error("request failure", e);
    } finally {
        try {
            connection.close();
        } catch (final IOException e) {
            LOG.warn("failure to close connection", e);
        }
    }

    // TODO restart
}

From source file:org.cloudata.core.common.io.CText.java

/** deserialize 
 *///from www .  j  av a 2  s.c  om
public void readFields(DataInput in) throws IOException {
    length = CWritableUtils.readVInt(in);
    setCapacity(length);
    in.readFully(bytes, 0, length);
}

From source file:org.cloudata.core.common.io.CText.java

/** Read a UTF8 encoded string from in
 *//*from w  w w .  j a va2s.  c o m*/
public static String readString(DataInput in) throws IOException {
    int length = CWritableUtils.readVInt(in);
    byte[] bytes = new byte[length];
    in.readFully(bytes, 0, length);
    return decode(bytes);
}

From source file:org.commoncrawl.util.TextBytes.java

/**
 * deserialize//w w w  . j  a v  a 2 s  . c o m
 */
public void readFields(DataInput in) throws IOException {
    int newLength = WritableUtils.readVInt(in);
    // ensure capacity
    setCapacity(newLength, false);
    // in case we need to, ensure we have a private copy of the underlying
    // array
    bytes.copyOnWrite();
    // read into the array
    in.readFully(bytes.get(), bytes.getOffset(), newLength);
    // reset count varaible
    bytes.setCount(newLength);
    // clear cached String pointer
    cachedUTF8 = null;
}

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

public void readFields(final DataInput in) throws IOException {
    setSize(0);/*from w w w. j av  a  2s. co  m*/
    setSize(readVInt(in));
    // LOG.info("Read Size="+size);
    in.readFully(bytes, 0, size);
    // LOG.info("PrettyBYtes: "+RHBytesWritable.bytesPretty(bytes));

    // readIntFields(in);
}

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

public void readIntFields(final DataInput in) throws IOException {
    setSize(0); // clear the old data
    final int d = in.readInt();
    setSize(d);//from  w w  w.jav a  2s . c o  m
    in.readFully(bytes, 0, size);
}