java.io.DataInput Java Examples

The following examples show how to use java.io.DataInput. 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: CompositeInputSplit.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * @throws IOException If the child InputSplit cannot be read, typically
 *                     for faliing access checks.
 */
@SuppressWarnings("unchecked")  // Generic array assignment
public void readFields(DataInput in) throws IOException {
  int card = WritableUtils.readVInt(in);
  if (splits == null || splits.length != card) {
    splits = new InputSplit[card];
  }
  Class<? extends InputSplit>[] cls = new Class[card];
  try {
    for (int i = 0; i < card; ++i) {
      cls[i] =
        Class.forName(Text.readString(in)).asSubclass(InputSplit.class);
    }
    for (int i = 0; i < card; ++i) {
      splits[i] = ReflectionUtils.newInstance(cls[i], null);
      splits[i].readFields(in);
    }
  } catch (ClassNotFoundException e) {
    throw (IOException)new IOException("Failed split init").initCause(e);
  }
}
 
Example #2
Source File: CompositeInputSplit.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * @throws IOException If the child InputSplit cannot be read, typically
 *                     for faliing access checks.
 */
@SuppressWarnings("unchecked")  // Generic array assignment
public void readFields(DataInput in) throws IOException {
  int card = WritableUtils.readVInt(in);
  if (splits == null || splits.length != card) {
    splits = new InputSplit[card];
  }
  Class<? extends InputSplit>[] cls = new Class[card];
  try {
    for (int i = 0; i < card; ++i) {
      cls[i] =
        Class.forName(Text.readString(in)).asSubclass(InputSplit.class);
    }
    for (int i = 0; i < card; ++i) {
      splits[i] = ReflectionUtils.newInstance(cls[i], null);
      splits[i].readFields(in);
    }
  } catch (ClassNotFoundException e) {
    throw (IOException)new IOException("Failed split init").initCause(e);
  }
}
 
Example #3
Source File: TupleWritable.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a bitset from the stream that has been written with
 * {@link #writeBitSet(DataOutput, int, BitSet)}.
 */
private static final void readBitSet(DataInput stream, int nbits, 
    BitSet bitSet) throws IOException {
  bitSet.clear();
  long initialBits = WritableUtils.readVLong(stream);
  long last = 0L;
  while (0L != initialBits) {
    last = Long.lowestOneBit(initialBits);
    initialBits ^= last;
    bitSet.set(Long.numberOfTrailingZeros(last));
  }
  
  for (int offset=Long.SIZE; offset < nbits; offset+=Byte.SIZE) {
    byte bits = stream.readByte();
    while (0 != bits) {
      last = Long.lowestOneBit(bits);
      bits ^= last;
      bitSet.set(Long.numberOfTrailingZeros(last) + offset);
    }
  }
}
 
Example #4
Source File: ByteBuffer.java    From systemds with Apache License 2.0 6 votes vote down vote up
public CacheBlock deserializeBlock() 
	throws IOException
{
	CacheBlock ret = null;
	
	if( !_shallow ) { //sparse matrix / string frame
		DataInput din = _matrix ? new CacheDataInput(_bdata) :
			new DataInputStream(new ByteArrayInputStream(_bdata));
		ret = _matrix ? new MatrixBlock() : new FrameBlock();
		ret.readFields(din);
	}
	else { //dense matrix/frame
		ret = _cdata;
	}
	
	return ret;
}
 
Example #5
Source File: StorageUtil.java    From tajo with Apache License 2.0 6 votes vote down vote up
/**
 * Similar to readFully(). Skips bytes in a loop.
 * @param in The DataInput to skip bytes from
 * @param len number of bytes to skip.
 * @throws java.io.IOException if it could not skip requested number of bytes
 * for any reason (including EOF)
 */
public static void skipFully(DataInput in, int len) throws IOException {
  int amt = len;
  while (amt > 0) {
    long ret = in.skipBytes(amt);
    if (ret == 0) {
      // skip may return 0 even if we're not at EOF.  Luckily, we can
      // use the read() method to figure out if we're at the end.
      int b = in.readByte();
      if (b == -1) {
        throw new EOFException( "Premature EOF from inputStream after " +
            "skipping " + (len - amt) + " byte(s).");
      }
      ret = 1;
    }
    amt -= ret;
  }
}
 
Example #6
Source File: ContainsKeyBulkExecutorMessage.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
  public void fromData(DataInput in)
      throws IOException, ClassNotFoundException {
    ser_deser_time = this.timeStatsEnabled ? (ser_deser_time == 0 ? -1 /*record*/
    : -2/*ignore nested call*/) : 0;
    super.fromData(in);
//    this.inKeys = InternalDataSerializer.readObject(in);
//    this.inRoutingObjects = InternalDataSerializer.readObject(in);
    this.keysToBucketIds = InternalDataSerializer.readObject(in);
    if ((flags & IS_PARTITIONED_TABLE) != 0) {
      this.prId = (int)InternalDataSerializer.readUnsignedVL(in);
    }
    else {
      this.regionPath = DataSerializer.readString(in);
    }
    if (this.timeStatsEnabled && ser_deser_time == -1) {
      this.ser_deser_time = XPLAINUtil.recordStdTiming(getTimestamp());
    }
  }
 
Example #7
Source File: MetricTimeSeries.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private static MetricTimeSeries fromBytes(byte[] buf, MetricSchema schema) throws IOException {
  MetricTimeSeries series = new MetricTimeSeries(schema);
  DataInput in = new DataInputStream(new ByteArrayInputStream(buf));
  int numTimeWindows = in.readInt();
  int bufferSize = in.readInt();
  for (int i = 0; i < numTimeWindows; i++) {
    long timeWindow = in.readLong();
    byte[] bytes = new byte[bufferSize];
    in.readFully(bytes);
    series.metricsValue.put(timeWindow, ByteBuffer.wrap(bytes));
    boolean[] hasValues = new boolean[schema.getNumMetrics()];
    for (int numMetrics = 0; numMetrics < schema.getNumMetrics(); numMetrics++) {
      hasValues[numMetrics] = true;
    }
    series.hasValue.put(timeWindow, hasValues);
  }
  return series;
}
 
Example #8
Source File: HiveKuduWritable.java    From HiveKudu-Handler with Apache License 2.0 6 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
    int size = in.readInt();
    if (size == -1) {
        return;
    }
    if (columnValues == null) {
        this.columnValues = new Object[size];
        this.columnTypes = new Type[size];
    } else {
        clear();
    }
    for (int i = 0; i < size; i++) {
        Type kuduType = WritableUtils.readEnum(in, Type.class);
        columnTypes[i] = kuduType;
        Object v = HiveKuduBridgeUtils.readObject(in, kuduType);
        columnValues[i] = v;
    }
}
 
Example #9
Source File: WARCRecord.java    From warc-hadoop with MIT License 6 votes vote down vote up
private static String readLine(DataInput in) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    boolean seenCR = false, seenCRLF = false;
    while (!seenCRLF) {
        if (out.size() > MAX_LINE_LENGTH) {
            throw new IllegalStateException("Exceeded maximum line length");
        }
        byte b = in.readByte();
        if (!seenCR && b == 13) {
            seenCR = true;
        } else if (seenCR && b == 10) {
            seenCRLF = true;
        } else {
            seenCR = false;
            out.write(b);
        }
    }
    return out.toString("UTF-8");
}
 
Example #10
Source File: Warp10InputSplit.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
  //
  // Read fetchers
  //
  
  int nfetchers = WritableUtils.readVInt(in);

  this.fetchers = new String[nfetchers];
  
  for (int i = 0; i < nfetchers; i++) {
    String currentFetcher = WritableUtils.readString(in);
    this.fetchers[i] = currentFetcher;
  }
  
  //
  // Read splits
  //
  
  int splitsize = WritableUtils.readVInt(in);

  this.splits = WritableUtils.readCompressedByteArray(in);
  this.complete = true;
}
 
Example #11
Source File: ReadRCFileBuilder.java    From kite with Apache License 2.0 6 votes vote down vote up
private Writable updateColumnValue(RCFileColumn column, BytesRefWritable bytesRef) throws IOException {
  if(bytesRef.getLength() == 0) {
    // This is a null field.
    return NullWritable.get();
  }
  Writable newColumnValue = column.newWritable();
  // Small optimization to bypass DataInput read if the column writable is
  // BytesRefWritable
  if (newColumnValue.getClass() == BytesRefWritable.class) {
    newColumnValue = bytesRef;
  } else {
    byte[] currentRowBytes = Arrays.copyOfRange(bytesRef.getData(),
        bytesRef.getStart(), bytesRef.getStart() + bytesRef.getLength());
    DataInput dataInput = ByteStreams.newDataInput(currentRowBytes);
    newColumnValue.readFields(dataInput);
  }
  return newColumnValue;
}
 
Example #12
Source File: RemovePersistentMemberMessage.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void fromData(DataInput in) throws IOException,
    ClassNotFoundException {
  super.fromData(in);
  regionPath = DataSerializer.readString(in);
  processorId = in.readInt();
  boolean hasId = in.readBoolean();
  if(hasId) {
    id = new PersistentMemberID();
    InternalDataSerializer.invokeFromData(id, in);
  }
  boolean hasInitializingId = in.readBoolean();
  if(hasInitializingId ) {
    initializingId = new PersistentMemberID();
    InternalDataSerializer.invokeFromData(initializingId, in);
  }
}
 
Example #13
Source File: GossipData.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void fromData(DataInput in) throws IOException,
    ClassNotFoundException {
  type=in.readInt();
  if (type == GEMFIRE_VERSION) {
    versionOrdinal = in.readShort();
  } else {
    group = in.readUTF();
    mbr = JChannel.getGfFunctions().readObject(in);
    mbrs = JChannel.getGfFunctions().readObject(in);
    //this.locators = (Vector)DataSerializer.readObject(in);
    hasDistributedSystem = in.readBoolean();
    this.floatingCoordinatorDisabled = in.readBoolean();
    this.networkPartitionDetectionEnabled = in.readBoolean();
    this.locators = JChannel.getGfFunctions().readObject(in);
    this.localAddress = JChannel.getGfFunctions().readObject(in);
  }
}
 
Example #14
Source File: SearchLoadAndWriteProcessor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void fromData(DataInput in)
throws IOException, ClassNotFoundException {
  super.fromData(in);
  this.regionName = in.readUTF();
  this.key = DataSerializer.readObject(in);
  this.timeoutMs = in.readInt();
  if ((flags & HAS_TTL) != 0) {
    this.ttl = (int)InternalDataSerializer.readSignedVL(in);
  }
  if ((flags & HAS_IDLE_TIME) != 0) {
    this.idleTime = (int)InternalDataSerializer.readSignedVL(in);
  }
  this.alwaysSendResult = (flags & ALWAYS_SEND_RESULT) != 0;
}
 
Example #15
Source File: GenerateData.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
  bytes = in.readLong();
  nLoc = in.readInt();
  if (null == locations || locations.length < nLoc) {
    locations = new String[nLoc];
  }
  for (int i = 0; i < nLoc; ++i) {
    locations[i] = Text.readString(in);
  }
}
 
Example #16
Source File: Nopol2015_0010_t.java    From coming with MIT License 5 votes vote down vote up
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
    // Read string pool.
    int poolSize = in.readUnsignedShort();
    String[] pool = new String[poolSize];
    for (int i=0; i<poolSize; i++) {
        pool[i] = in.readUTF();
    }

    int size = in.readInt();
    long[] transitions = new long[size];
    int[] wallOffsets = new int[size];
    int[] standardOffsets = new int[size];
    String[] nameKeys = new String[size];
    
    for (int i=0; i<size; i++) {
        transitions[i] = readMillis(in);
        wallOffsets[i] = (int)readMillis(in);
        standardOffsets[i] = (int)readMillis(in);
        try {
            int index;
            if (poolSize < 256) {
                index = in.readUnsignedByte();
            } else {
                index = in.readUnsignedShort();
            }
            nameKeys[i] = pool[index];
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new IOException("Invalid encoding");
        }
    }

    DSTZone tailZone = null;
    if (in.readBoolean()) {
        tailZone = DSTZone.readFrom(in, id);
    }

    return new PrecalculatedZone
        (id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
 
Example #17
Source File: ResponseAttachmentInputStreamSupportTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static DataInput getDataInput(int operationId, int streamIndex) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeByte(ModelControllerProtocol.PARAM_OPERATION);
    dos.writeInt(operationId);
    dos.writeByte(ModelControllerProtocol.PARAM_INPUTSTREAM_INDEX);
    dos.writeInt(streamIndex);
    dos.flush();
    return new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
}
 
Example #18
Source File: ColumnFamilySerializer.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public UUID deserializeCfId(DataInput in, int version) throws IOException
{
    UUID cfId = UUIDSerializer.serializer.deserialize(in, version);
    if (Schema.instance.getCF(cfId) == null)
        throw new UnknownColumnFamilyException("Couldn't find cfId=" + cfId, cfId);

    return cfId;
}
 
Example #19
Source File: ZoneInfoFile.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static long readEpochSec(DataInput in) throws IOException {
    int hiByte = in.readByte() & 255;
    if (hiByte == 255) {
        return in.readLong();
    } else {
        int midByte = in.readByte() & 255;
        int loByte = in.readByte() & 255;
        long tot = ((hiByte << 16) + (midByte << 8) + loByte);
        return (tot * 900) - 4575744000L;
    }
}
 
Example #20
Source File: ContainsUniqueKeyExecutorMessage.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void fromData(DataInput in)
    throws IOException, ClassNotFoundException {
  super.fromData(in);
  ser_deser_time = this.timeStatsEnabled ? (ser_deser_time == 0 ? -1 /*record*/
      : -2/*ignore nested call*/) : 0;
  this.referenceKeyColumnIndexes = DataSerializer.readIntArray(in);
  // recording end of de-serialization here instead of AbstractOperationMessage.
  if (this.timeStatsEnabled && ser_deser_time == -1) {
    this.ser_deser_time = XPLAINUtil.recordStdTiming(getTimestamp());
  }
}
 
Example #21
Source File: TCPEndpoint.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new endpoint from input stream data.
 * @param in the input stream
 */
public static TCPEndpoint readHostPortFormat(DataInput in)
    throws IOException
{
    String host = in.readUTF();
    int port = in.readInt();
    return new TCPEndpoint(host, port);
}
 
Example #22
Source File: GfxdSetGatewayConflictResolverMessage.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void fromData(DataInput in)
    throws IOException, ClassNotFoundException {
  super.fromData(in);
  this.implementation = DataSerializer.readString(in);
  this.initInfoStr = DataSerializer.readString(in);
}
 
Example #23
Source File: ResourceAdvisor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
  super.fromData(in);
  
  final long heapBytesUsed = in.readLong();
  MemoryState heapState = MemoryState.fromData(in);
  MemoryThresholds heapThresholds = MemoryThresholds.fromData(in);
  setHeapData(heapBytesUsed, heapState, heapThresholds);
  
  final long offHeapBytesUsed = in.readLong();
  MemoryState offHeapState = MemoryState.fromData(in);
  MemoryThresholds offHeapThresholds = MemoryThresholds.fromData(in);
  setOffHeapData(offHeapBytesUsed, offHeapState, offHeapThresholds);
}
 
Example #24
Source File: TzdbResourceZoneRulesProvider.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Modified from {@link java.time.zone.Ser#read}.
 */
private static Object serRead(DataInput in) throws IOException {
    byte type = in.readByte();
    switch (type) {
    case ZRULES:
        return invokeReadExternal(ZoneRules.class, in); // ZoneRules.readExternal(in)
    case ZOT:
        return invokeReadExternal(ZoneOffsetTransition.class, in); // ZoneOffsetTransition.readExternal(in)
    case ZOTRULE:
        return invokeReadExternal(ZoneOffsetTransitionRule.class, in); // ZoneOffsetTransitionRule.readExternal(in)
    default:
        throw new StreamCorruptedException("Unknown serialized type");
    }
}
 
Example #25
Source File: InnerClasses.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Construct object from input stream.
 *
 * @param name_index Index in constant pool to CONSTANT_Utf8
 * @param length Content length in bytes
 * @param input Input stream
 * @param constant_pool Array of constants
 * @throws IOException
 */
InnerClasses(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool)
        throws IOException {
    this(name_index, length, (InnerClass[]) null, constant_pool);
    final int number_of_classes = input.readUnsignedShort();
    innerClasses = new InnerClass[number_of_classes];
    for (int i = 0; i < number_of_classes; i++) {
        innerClasses[i] = new InnerClass(input);
    }
}
 
Example #26
Source File: ExecutionPlanMessage.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void fromData(DataInput in)
    throws IOException, ClassNotFoundException {
  super.fromData(in);
  this.schema = DataSerializer.readString(in);
  this.stmtUUID = DataSerializer.readString(in);
  this.xmlForm = XMLForms.values()[DataSerializer.readInteger(in)];
  this.embedXslFileName = DataSerializer.readString(in);
}
 
Example #27
Source File: Cardumen_00188_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Decodes a built DateTimeZone from the given stream, as encoded by
 * writeTo.
 *
 * @param in input stream to read encoded DateTimeZone from.
 * @param id time zone id to assign
 */
public static DateTimeZone readFrom(InputStream in, String id) throws IOException {
    if (in instanceof DataInput) {
        return readFrom((DataInput)in, id);
    } else {
        return readFrom((DataInput)new DataInputStream(in), id);
    }
}
 
Example #28
Source File: LinkedResultSet.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void fromData(DataInput in) throws IOException, ClassNotFoundException
{
  int size = in.readInt();
  this.elementType = (ObjectType)DataSerializer.readObject(in);
  for (int j = size; j > 0; j--) {
    this.add(DataSerializer.readObject(in));
  }
}
 
Example #29
Source File: SerialIO.java    From jenetics with Apache License 2.0 5 votes vote down vote up
private static long innerLongDecode(long l, final DataInput in)
	throws IOException
{
	int b = in.readByte() & 0xFF;
	l ^= (b & 0x7FL) << 28;
	if (b > 0x7F) {
		b = in.readByte() & 0xFF;
		l ^= (b & 0x7FL) << 35;
		if (b > 0x7F) {
			b = in.readByte() & 0xFF;
			l ^= (b & 0x7FL) << 42;
			if (b > 0x7F) {
				b = in.readByte() & 0xFF;
				l ^= (b & 0x7FL) << 49;
				if (b > 0x7F) {
					b = in.readByte() & 0xFF;
					l ^= (b & 0x7FL) << 56;
					if (b > 0x7F) {
						b = in.readByte() & 0xFF;
						l ^= (b & 0x7FL) << 63;
						if (b > 0x7F) {
							throw new IOException("Invalid long encoding.");
						}
					}
				}
			}
		}
	}
	return l;
}
 
Example #30
Source File: Arja_00172_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Decodes a built DateTimeZone from the given stream, as encoded by
 * writeTo.
 *
 * @param in input stream to read encoded DateTimeZone from.
 * @param id time zone id to assign
 */
public static DateTimeZone readFrom(InputStream in, String id) throws IOException {
    if (in instanceof DataInput) {
        return readFrom((DataInput)in, id);
    } else {
        return readFrom((DataInput)new DataInputStream(in), id);
    }
}