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

The following examples show how to use java.io.DataInput#skipBytes() . 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: 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 2
Source File: PdxReaderImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static PdxInputStream createDis(DataInput in, int len) throws IOException {
  boolean isBBIS = in instanceof ByteBufferInputStream;
  PdxInputStream bbis;
  if (isBBIS) {
    // Note, it is ok for our immutable bbis to wrap a mutable bbis
    // because PdxReaderImpl is only used for a quick deserialization.
    // PdxInstanceImpl has its own flavor of createDis since it can
    // live longer.
    bbis = new PdxInputStream((ByteBufferInputStream) in, len);
    int bytesSkipped = in.skipBytes(len);
    int bytesRemaining = len - bytesSkipped;
    while (bytesRemaining > 0) {
      in.readByte();
      bytesRemaining--;
    }
  } else {
    byte[] bytes = new byte[len];
    in.readFully(bytes);
    bbis = new PdxInputStream(bytes);
  }
  return bbis;
}
 
Example 3
Source File: GridmixRecord.java    From hadoop 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 4
Source File: XmlDecompressor.java    From android-classyshark with Apache License 2.0 6 votes vote down vote up
private void parseCDataTag(StringBuilder sb, DataInput dis, List<String> strings, int ident)
        throws IOException {
    //Skipping 3 unknowns integers:
    dis.skipBytes(8);
    int nameStringIndex = dis.readInt();
    //Skipping 2 more unknown integers.
    dis.skipBytes(8);

    if (appendCData) {
        sb.append(SPACE_FILL, 0, ident * IDENT_SIZE);
        sb.append("<![CDATA[\n");
        sb.append(SPACE_FILL, 0, ident * IDENT_SIZE + 1);
        sb.append(strings.get(nameStringIndex));
        sb.append(SPACE_FILL, 0, ident * IDENT_SIZE);
        sb.append("]]>\n");
    }
}
 
Example 5
Source File: GridmixRecord.java    From RDFS 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: FileUtils.java    From hadoop-sstable with Apache License 2.0 5 votes vote down vote up
public static void skipBytesFully(DataInput in, int bytes) throws IOException {
    int n = 0;
    while (n < bytes) {
        int skipped = in.skipBytes(bytes - n);
        if (skipped == 0)
            throw new EOFException("EOF after " + n + " bytes out of " + bytes);
        n += skipped;
    }
}
 
Example 7
Source File: Res9patchStreamDecoder.java    From jadx with Apache License 2.0 5 votes vote down vote up
private void find9patchChunk(DataInput di) throws IOException {
	di.skipBytes(8);
	while (true) {
		int size;
		try {
			size = di.readInt();
		} catch (IOException ex) {
			throw new JadxRuntimeException("Cant find nine patch chunk", ex);
		}
		if (di.readInt() == NP_CHUNK_TYPE) {
			return;
		}
		di.skipBytes(size + 4);
	}
}
 
Example 8
Source File: FileUtils.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static void skipBytesFully(DataInput in, int bytes) throws IOException
{
    int n = 0;
    while (n < bytes)
    {
        int skipped = in.skipBytes(bytes - n);
        if (skipped == 0)
            throw new EOFException("EOF after " + n + " bytes out of " + bytes);
        n += skipped;
    }
}
 
Example 9
Source File: StringRecord.java    From stratosphere with Apache License 2.0 5 votes vote down vote up
public static void skipFully(final DataInput in, final int len) throws IOException {
	int total = 0;
	int cur = 0;

	while ((total < len) && ((cur = in.skipBytes(len - total)) > 0)) {
		total += cur;
	}

	if (total < len) {
		throw new IOException("Not able to skip " + len + " bytes, possibly " + "due to end of input.");
	}
}
 
Example 10
Source File: TestMapCollection.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void readFields(DataInput in) throws IOException {
  if (expectedlen != 0) {
    int bytesread;
    if (pedantic) {
      for (int i = 0; i < expectedlen; ++i)
        assertEquals("Invalid byte at " + i, c, in.readByte());
      bytesread = expectedlen;
    } else {
      bytesread = in.skipBytes(expectedlen);
    }
    assertEquals("Too few bytes in record", expectedlen, bytesread);
  }
  // cannot verify that the stream has been exhausted
}
 
Example 11
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 12
Source File: BytesTool.java    From freeinternals with Apache License 2.0 5 votes vote down vote up
@Deprecated
public static void skipBytes(final DataInput di, final int skip) throws IOException {
    long skippedBytes = di.skipBytes(skip);
    if (skippedBytes != skip) {
        throw new IOException(String.format("Failed to skip %d bytes, actual bytes skipped %d", skip, skippedBytes));
    }
}
 
Example 13
Source File: Res9patchStreamDecoder.java    From Box with Apache License 2.0 5 votes vote down vote up
private void find9patchChunk(DataInput di) throws IOException {
	di.skipBytes(8);
	while (true) {
		int size;
		try {
			size = di.readInt();
		} catch (IOException ex) {
			throw new JadxRuntimeException("Cant find nine patch chunk", ex);
		}
		if (di.readInt() == NP_CHUNK_TYPE) {
			return;
		}
		di.skipBytes(size + 4);
	}
}
 
Example 14
Source File: ZclDataUtil.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private static Object readBag(DataInput input) throws IOException {
   log.warn("cannot currently decode zigbee bag data types, skipping");

   Object len = readBit16(input, true, false);
   if (len == NONE) return NONE;

   int length = ((Short)len).shortValue() & 0xFFFF;
   input.skipBytes(length);

   return NONE;
}
 
Example 15
Source File: ZclDataUtil.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private static Object readSet(DataInput input) throws IOException {
   log.warn("cannot currently decode zigbee set data types, skipping");

   Object len = readBit16(input, true, false);
   if (len == NONE) return NONE;

   int length = ((Short)len).shortValue() & 0xFFFF;
   input.skipBytes(length);

   return NONE;
}
 
Example 16
Source File: ZclDataUtil.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private static Object readArray(DataInput input) throws IOException {
   log.warn("cannot currently decode zigbee array data types, skipping");

   Object len = readBit16(input, true, false);
   if (len == NONE) return NONE;

   int length = ((Short)len).shortValue() & 0xFFFF;
   input.skipBytes(length);

   return NONE;
}
 
Example 17
Source File: Res9patchStreamDecoder.java    From Box with Apache License 2.0 5 votes vote down vote up
private void find9patchChunk(DataInput di) throws IOException {
	di.skipBytes(8);
	while (true) {
		int size;
		try {
			size = di.readInt();
		} catch (IOException ex) {
			throw new JadxRuntimeException("Cant find nine patch chunk", ex);
		}
		if (di.readInt() == NP_CHUNK_TYPE) {
			return;
		}
		di.skipBytes(size + 4);
	}
}
 
Example 18
Source File: VerifyClassLinkage.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void skip(DataInput input, int bytes) throws IOException {
    int skipped = input.skipBytes(bytes);
    if (skipped != bytes) {
        throw new IOException("Truncated class file");
    }
}
 
Example 19
Source File: TezEvent.java    From tez with Apache License 2.0 4 votes vote down vote up
private void deserializeEvent(DataInput in) throws IOException {
  if (!in.readBoolean()) {
    event = null;
    return;
  }
  eventType = EventType.values()[in.readInt()];
  eventReceivedTime = in.readLong();
  if (eventType.equals(EventType.TASK_STATUS_UPDATE_EVENT)) {
    // TODO NEWTEZ convert to PB
    event = new TaskStatusUpdateEvent();
    ((TaskStatusUpdateEvent)event).readFields(in);
  } else {
    int eventBytesLen = in.readInt();
    byte[] eventBytes;
    CodedInputStream input;
    int startOffset = 0;
    if (in instanceof DataInputBuffer) {
      eventBytes = ((DataInputBuffer)in).getData();
      startOffset = ((DataInputBuffer) in).getPosition();
    } else {
      eventBytes = new byte[eventBytesLen];
      in.readFully(eventBytes);
    }
    input = CodedInputStream.newInstance(eventBytes, startOffset, eventBytesLen);
    switch (eventType) {
    case CUSTOM_PROCESSOR_EVENT:
      CustomProcessorEventProto cpProto =
          CustomProcessorEventProto.parseFrom(input);
      event = ProtoConverters.convertCustomProcessorEventFromProto(cpProto);
      break;
    case DATA_MOVEMENT_EVENT:
      DataMovementEventProto dmProto =
          DataMovementEventProto.parseFrom(input);
      event = ProtoConverters.convertDataMovementEventFromProto(dmProto);
      break;
    case COMPOSITE_ROUTED_DATA_MOVEMENT_EVENT:
      CompositeRoutedDataMovementEventProto edmProto =
          CompositeRoutedDataMovementEventProto.parseFrom(eventBytes);
    event = ProtoConverters.convertCompositeRoutedDataMovementEventFromProto(edmProto);
    break;
    case COMPOSITE_DATA_MOVEMENT_EVENT:
      CompositeEventProto cProto = CompositeEventProto.parseFrom(input);
      event = ProtoConverters.convertCompositeDataMovementEventFromProto(cProto);
      break;
    case VERTEX_MANAGER_EVENT:
      VertexManagerEventProto vmProto = VertexManagerEventProto.parseFrom(input);
      event = ProtoConverters.convertVertexManagerEventFromProto(vmProto);
      break;
    case INPUT_READ_ERROR_EVENT:
      InputReadErrorEventProto ideProto =
          InputReadErrorEventProto.parseFrom(input);
      event = InputReadErrorEvent.create(ideProto.getDiagnostics(),
          ideProto.getIndex(), ideProto.getVersion());
      break;
    case TASK_ATTEMPT_FAILED_EVENT:
      TaskAttemptFailedEventProto tfProto =
          TaskAttemptFailedEventProto.parseFrom(input);
      event = new TaskAttemptFailedEvent(tfProto.getDiagnostics(),
          TezConverterUtils.failureTypeFromProto(tfProto.getTaskFailureType()));
      break;
    case TASK_ATTEMPT_KILLED_EVENT:
      TaskAttemptKilledEventProto tkProto = TaskAttemptKilledEventProto.parseFrom(input);
      event = new TaskAttemptKilledEvent(tkProto.getDiagnostics());
      break;
    case TASK_ATTEMPT_COMPLETED_EVENT:
      event = new TaskAttemptCompletedEvent();
      break;
    case INPUT_FAILED_EVENT:
      InputFailedEventProto ifProto =
          InputFailedEventProto.parseFrom(input);
      event = InputFailedEvent.create(ifProto.getTargetIndex(), ifProto.getVersion());
      break;
    case ROOT_INPUT_DATA_INFORMATION_EVENT:
      RootInputDataInformationEventProto difProto = RootInputDataInformationEventProto
          .parseFrom(input);
      event = ProtoConverters.convertRootInputDataInformationEventFromProto(difProto);
      break;
    case ROOT_INPUT_INITIALIZER_EVENT:
      EventProtos.RootInputInitializerEventProto riiProto = EventProtos.RootInputInitializerEventProto.parseFrom(input);
      event = ProtoConverters.convertRootInputInitializerEventFromProto(riiProto);
      break;
    default:
      // RootInputUpdatePayload event not wrapped in a TezEvent.
      throw new TezUncheckedException("Unexpected TezEvent"
         + ", type=" + eventType);
    }
    if (in instanceof DataInputBuffer) {
      // Skip so that position is updated
      int skipped = in.skipBytes(eventBytesLen);
      if (skipped != eventBytesLen) {
        throw new TezUncheckedException("Expected to skip " + eventBytesLen + " bytes. Actually skipped = " + skipped);
      }
    }
  }
}
 
Example 20
Source File: Utility.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
static void skipFully(final DataInput file, final int length) throws IOException {
    int total = file.skipBytes(length);
    if (total != length) {
        throw new EOFException();
    }
}