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

The following examples show how to use java.io.DataInput#skipBytes() . These examples are extracted from open source projects. 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
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 2
Source Project: RDFS   File: GridmixRecord.java    License: 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 3
Source Project: hadoop   File: GridmixRecord.java    License: 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 Project: gemfirexd-oss   File: PdxReaderImpl.java    License: 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 5
Source Project: big-c   File: GridmixRecord.java    License: 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 Project: Box   File: Res9patchStreamDecoder.java    License: 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 7
Source Project: arcusplatform   File: ZclDataUtil.java    License: 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 8
Source Project: arcusplatform   File: ZclDataUtil.java    License: 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 9
Source Project: arcusplatform   File: ZclDataUtil.java    License: 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 10
Source Project: Box   File: Res9patchStreamDecoder.java    License: 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 11
Source Project: freeinternals   File: BytesTool.java    License: 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 12
Source Project: waterdrop   File: SerializedConfigValue.java    License: 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 13
Source Project: RDFS   File: TestMapCollection.java    License: 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 14
Source Project: stratosphere   File: StringRecord.java    License: 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 15
Source Project: stratio-cassandra   File: FileUtils.java    License: 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 16
Source Project: jadx   File: Res9patchStreamDecoder.java    License: 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 17
Source Project: hadoop-sstable   File: FileUtils.java    License: 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 18
Source Project: Tomcat8-Source-Read   File: Utility.java    License: 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();
    }
}
 
Example 19
Source Project: tez   File: TezEvent.java    License: 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 Project: netbeans   File: VerifyClassLinkage.java    License: 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");
    }
}