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:Main.java

public static byte[] readByteBuffer(DataInput in) throws Exception {
    int b = in.readByte();
    if (b == 1) {
        b = in.readInt();//from   w  ww .  j  a v a  2 s .  c  om
        byte[] buf = new byte[b];
        in.readFully(buf, 0, buf.length);
        return buf;
    }
    return null;
}

From source file:com.icloud.framework.core.util.FBUtilities.java

public static ByteBuffer readShortByteArray(DataInput in) throws IOException {
    int length = readShortLength(in);
    ByteBuffer bb = ByteBuffer.allocate(length);
    in.readFully(bb.array(), bb.position(), bb.remaining());
    return bb;//from   ww  w . j ava  2 s  .co m
}

From source file:com.icloud.framework.core.util.FBUtilities.java

public static ByteBuffer readByteArray(DataInput in) throws IOException {
    int length = in.readInt();
    if (length < 0) {
        throw new IOException("Corrupt (negative) value length encountered");
    }//from w ww  .  jav  a 2 s.com

    ByteBuffer bb = ByteBuffer.allocate(length);
    if (length > 0) {
        in.readFully(bb.array(), bb.position(), bb.remaining());
    }
    return bb;
}

From source file:io.Text.java

/** Read a UTF8 encoded string from in
 *///from  w  ww  .  j a v a  2  s  .co m
public static String readString(DataInput in) throws IOException {
    int length = WritableUtils.readVInt(in);
    byte[] bytes = new byte[length];
    in.readFully(bytes, 0, length);
    return decode(bytes);
}

From source file:com.krawler.common.util.ByteUtil.java

public static String readUTF8(DataInput in) throws IOException {
    int len = in.readInt();
    if (len > MAX_STRING_LEN) {
        throw new IOException(
                "String length " + len + " is too long in ByteUtil.writeUTF8(); max=" + MAX_STRING_LEN);
    } else if (len > 0) {
        byte[] buf = new byte[len];
        in.readFully(buf, 0, len);
        return new String(buf, "UTF-8");
    } else if (len == 0) {
        return "";
    } else if (len == -1) {
        return null;
    } else {/*  w  w w. j av a  2 s.  c om*/
        throw new IOException("Invalid length " + len + " in ByteUtil.readUTF8()");
    }
}

From source file:libra.common.hadoop.io.datatypes.CompressedSequenceWritable.java

@Override
public void readFields(DataInput in) throws IOException {
    this.seqLength = in.readByte();
    int byteLen = SequenceHelper.getCompressedSize(this.seqLength);
    this.compressedSequence = new byte[byteLen];
    in.readFully(this.compressedSequence, 0, byteLen);
}

From source file:com.marklogic.mapreduce.DatabaseDocument.java

@Override
public void readFields(DataInput in) throws IOException {
    int ordinal = in.readInt();
    contentType = ContentType.valueOf(ordinal);
    int length = WritableUtils.readVInt(in);
    content = new byte[length];
    in.readFully(content, 0, length);
}

From source file:io.UTF8.java

public void readFields(DataInput in) throws IOException {
    length = in.readUnsignedShort();/*w  w w.ja  v  a2 s  . c o m*/
    if (bytes == null || bytes.length < length)
        bytes = new byte[length];
    in.readFully(bytes, 0, length);
}

From source file:edu.umd.cloud9.collection.wikipedia.WikipediaPage.java

/**
 * Serializes this object.// ww  w .ja va  2 s.  c o  m
 */
public void readFields(DataInput in) throws IOException {
    int length = WritableUtils.readVInt(in);
    byte[] bytes = new byte[length];
    in.readFully(bytes, 0, length);
    WikipediaPage.readPage(this, new String(bytes));
    language = in.readUTF();
}

From source file:com.buaa.cfs.io.UTF8.java

@Override
public void readFields(DataInput in) throws IOException {
    length = in.readUnsignedShort();//  w w w  .j a v a2  s.  c  om
    if (bytes == null || bytes.length < length)
        bytes = new byte[length];
    in.readFully(bytes, 0, length);
}