Java Code Examples for java.io.DataInput#readFully()

The following examples show how to use java.io.DataInput#readFully() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BloomFilter.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
  super.readFields(in);
  bits = new BitSet(this.vectorSize);
  byte[] bytes = new byte[getNBytes()];
  in.readFully(bytes);
  for(int i = 0, byteIndex = 0, bitIndex = 0; i < vectorSize; i++, bitIndex++) {
    if (bitIndex == 8) {
      bitIndex = 0;
      byteIndex++;
    }
    if ((bytes[byteIndex] & bitvalues[bitIndex]) != 0) {
      bits.set(i);
    }
  }
}
 
Example 2
Source File: HybridMemorySegment.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public final void put(DataInput in, int offset, int length) throws IOException {
	if (address <= addressLimit) {
		if (heapMemory != null) {
			in.readFully(heapMemory, offset, length);
		}
		else {
			while (length >= 8) {
				putLongBigEndian(offset, in.readLong());
				offset += 8;
				length -= 8;
			}
			while (length > 0) {
				put(offset, in.readByte());
				offset++;
				length--;
			}
		}
	}
	else {
		throw new IllegalStateException("segment has been freed");
	}
}
 
Example 3
Source File: TransactionEditCodecs.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Override
public void decode(TransactionEdit dest, DataInput in) throws IOException {
  dest.setWritePointer(in.readLong());
  int stateIdx = in.readInt();
  try {
    dest.setState(TransactionEdit.State.values()[stateIdx]);
  } catch (ArrayIndexOutOfBoundsException e) {
    throw new IOException("State enum ordinal value is out of range: " + stateIdx);
  }
  dest.setExpiration(in.readLong());
  dest.setCommitPointer(in.readLong());
  dest.setCanCommit(in.readBoolean());
  int changeSize = in.readInt();
  Set<ChangeId> changes = Sets.newHashSet();
  for (int i = 0; i < changeSize; i++) {
    int currentLength = in.readInt();
    byte[] currentBytes = new byte[currentLength];
    in.readFully(currentBytes);
    changes.add(new ChangeId(currentBytes));
  }
  dest.setChanges(changes);
  // 1st version did not store this info. It is safe to set firstInProgress to 0, it may decrease performance until
  // this tx is finished, but correctness will be preserved.
  dest.setVisibilityUpperBound(0);
}
 
Example 4
Source File: AtomWritable.java    From aegisthus with Apache License 2.0 6 votes vote down vote up
@Override
public void readFields(DataInput dis) throws IOException {
    int length = dis.readInt();
    byte[] bytes = new byte[length];
    dis.readFully(bytes);
    this.key = bytes;
    this.deletedAt = dis.readLong();

    boolean hasAtom = dis.readBoolean();
    if (hasAtom) {
        this.atom = serializer.deserializeFromSSTable(
                dis, ColumnSerializer.Flag.PRESERVE_SIZE, Integer.MIN_VALUE, version
        );
    } else {
        this.atom = null;
    }
}
 
Example 5
Source File: GridmixRecord.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
  size = WritableUtils.readVInt(in);
  int payload = size - WritableUtils.getVIntSize(size);
  if (payload > Long.SIZE / Byte.SIZE) {
    seed = in.readLong();
    payload -= Long.SIZE / Byte.SIZE;
  } else {
    Arrays.fill(literal, (byte)0);
    in.readFully(literal, 0, payload);
    dib.reset(literal, 0, literal.length);
    seed = dib.readLong();
    payload = 0;
  }
  final int vBytes = in.skipBytes(payload);
  if (vBytes != payload) {
    throw new EOFException("Expected " + payload + ", read " + vBytes);
  }
}
 
Example 6
Source File: Bytes.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a fixed-size field and interprets it as a string padded with zeros.
 */
public static String readStringFixedSize(final DataInput in, int size) throws IOException {
    byte[] b = new byte[size];
    in.readFully(b);
    int n = b.length;
    while (n > 0 && b[n - 1] == 0)
        --n;

    return toString(b, 0, n);
}
 
Example 7
Source File: SerializedConfigValue.java    From waterdrop with Apache License 2.0 5 votes vote down vote up
private static void skipField(DataInput in) throws IOException {
    int len = in.readInt();
    // skipBytes doesn't have to block
    int skipped = in.skipBytes(len);
    if (skipped < len) {
        // wastefully use readFully() if skipBytes didn't work
        byte[] bytes = new byte[(len - skipped)];
        in.readFully(bytes);
    }
}
 
Example 8
Source File: GeoWaveInputKey.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void readFields(final DataInput input) throws IOException {
  internalAdapterId = input.readShort();
  final int dataIdLength = input.readInt();
  final byte[] dataIdBytes = new byte[dataIdLength];
  input.readFully(dataIdBytes);
  dataId = new ByteArray(dataIdBytes);
}
 
Example 9
Source File: GridCoverageWritable.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void readFields(final DataInput input) throws IOException {
  final int rasterTileSize = Varint.readUnsignedVarInt(input);
  final byte[] rasterTileBinary = new byte[rasterTileSize];
  input.readFully(rasterTileBinary);
  rasterTile = new RasterTile();
  rasterTile.fromBinary(rasterTileBinary);
  minX = input.readDouble();
  maxX = input.readDouble();
  minY = input.readDouble();
  maxY = input.readDouble();
  final int crsStrSize = Varint.readUnsignedVarInt(input);

  if (crsStrSize > 0) {
    final byte[] crsStrBytes = new byte[crsStrSize];
    input.readFully(crsStrBytes);
    final String crsStr = StringUtils.stringFromBinary(crsStrBytes);
    try {
      crs = CRS.decode(crsStr);
    } catch (final FactoryException e) {
      LOGGER.error("Unable to decode " + crsStr + " CRS", e);
      throw new RuntimeException("Unable to decode " + crsStr + " CRS", e);
    }
  } else {
    crs = GeometryUtils.getDefaultCRS();
  }
}
 
Example 10
Source File: Content.java    From nutch-htmlunit with Apache License 2.0 5 votes vote down vote up
private final void readFieldsCompressed(DataInput in) throws IOException {
  byte oldVersion = in.readByte();
  switch (oldVersion) {
  case 0:
  case 1:
    url = Text.readString(in); // read url
    base = Text.readString(in); // read base

    content = new byte[in.readInt()]; // read content
    in.readFully(content);

    contentType = Text.readString(in); // read contentType
    // reconstruct metadata
    int keySize = in.readInt();
    String key;
    for (int i = 0; i < keySize; i++) {
      key = Text.readString(in);
      int valueSize = in.readInt();
      for (int j = 0; j < valueSize; j++) {
        metadata.add(key, Text.readString(in));
      }
    }
    break;
  case 2:
    url = Text.readString(in); // read url
    base = Text.readString(in); // read base

    content = new byte[in.readInt()]; // read content
    in.readFully(content);

    contentType = Text.readString(in); // read contentType
    metadata.readFields(in); // read meta data
    break;
  default:
    throw new VersionMismatchException((byte)2, oldVersion);
  }

}
 
Example 11
Source File: StorageSerialization.java    From PalDB with Apache License 2.0 5 votes vote down vote up
private static int[] deserializeArrayIntCompressed(DataInput is)
    throws IOException {
  int size = LongPacker.unpackInt(is);
  byte[] b = new byte[size];
  is.readFully(b);
  return Snappy.uncompressIntArray(b);
}
 
Example 12
Source File: Text.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/** deserialize
 */
public void readFields(DataInput in) throws IOException {
    int newLength = WritableUtils.readVInt(in);
    setCapacity(newLength, false);
    in.readFully(bytes, 0, newLength);
    length = newLength;
}
 
Example 13
Source File: JSON.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
final void readData(DataInput in, boolean reuseArrayIfPossible)
    throws IOException {
  int length = in.readUnsignedShort();
  byte[] b = new byte[length];
  in.readFully(b);
  try {
    setValue(new String(b));
  } catch (StandardException e) {
    // FIXME: may not always be IOException
    throw new IOException(e);
  }
}
 
Example 14
Source File: SerializerUtil.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public static BytesRef readBytesRef(DataInput in) throws IOException {
  int length = in.readInt();
  BytesRef bytes = new BytesRef(length);
  in.readFully(bytes.bytes);
  bytes.offset = 0;
  bytes.length = length;
  return bytes;
}
 
Example 15
Source File: MerkleTree.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public Inner deserialize(DataInput in, int version) throws IOException
{
    int hashLen = in.readInt();
    byte[] hash = hashLen >= 0 ? new byte[hashLen] : null;
    if (hash != null)
        in.readFully(hash);
    Token token = Token.serializer.deserialize(in);
    Hashable lchild = Hashable.serializer.deserialize(in, version);
    Hashable rchild = Hashable.serializer.deserialize(in, version);
    return new Inner(token, lchild, rchild);
}
 
Example 16
Source File: DataReaderWriter.java    From spork with Apache License 2.0 4 votes vote down vote up
public static String bytesToBigCharArray(DataInput in) throws IOException{
    int size = in.readInt();
    byte[] ba = new byte[size];
    in.readFully(ba);
    return new String(ba, DataReaderWriter.UTF8);
}
 
Example 17
Source File: AppendDictSliceKey.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public void readFields(DataInput in) throws IOException {
    key = new byte[in.readInt()];
    in.readFully(key);
}
 
Example 18
Source File: ParquetInputSplit.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
private static byte[] readArray(DataInput in) throws IOException {
  int len = in.readInt();
  byte[] bytes = new byte[len];
  in.readFully(bytes);
  return bytes;
}
 
Example 19
Source File: AllocatedFilter.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException{
    addressMatch=new byte[in.readInt()];
    in.readFully(addressMatch);
}
 
Example 20
Source File: EncodingTools.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Read a String from a DataInput.
 * 
 * @param in
 *            The DataInput to read.
 * @return The string that was read.
 * @throws IOException
 *             If the DataInput blows up.
 * @throws EOFException
 *             If the end of the stream is reached.
 */
public static String readString(DataInput in) throws IOException {
	int length = readInt32(in);
	byte[] buffer = new byte[length];
	in.readFully(buffer);
	return new String(buffer, CHARSET);
}