Java Code Examples for java.io.DataInputStream#skip()

The following examples show how to use java.io.DataInputStream#skip() . 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: ReinterpretDataStreamAsKeyedStreamITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	super.open(parameters);
	int subtaskIdx = getRuntimeContext().getIndexOfThisSubtask();
	File partitionFile = allPartitions.get(subtaskIdx);
	fileLength = partitionFile.length();
	waitForFailurePos = fileLength * 3 / 4;
	din = new DataInputStream(
		new BufferedInputStream(
			new FileInputStream(partitionFile)));

	long toSkip = position;
	while (toSkip > 0L) {
		toSkip -= din.skip(toSkip);
	}
}
 
Example 2
Source File: SougouScelReader.java    From ThesaurusParser with MIT License 6 votes vote down vote up
protected String readString(DataInputStream input,int pos,int[] reads) throws IOException {
    int read=reads[0];
    input.skip(pos-read);
    read=pos;
    output.reset();
    while(true) {
        int c1 = input.read();
        int c2 = input.read();
        read+=2;
        if(c1==0 && c2==0) {
            break;
        } else {
            output.write(c1);
            output.write(c2);
        }
    }
    reads[0]=read;
    return new String(output.toByteArray(),encoding);
}
 
Example 3
Source File: RealClassBuilder.java    From amidst with GNU General Public License v3.0 6 votes vote down vote up
private int readMethodsAndConstructors(
		DataInputStream stream,
		int numberOfMethodsAndConstructors,
		RealClassConstant<?>[] constants,
		List<ReferenceIndex> methodIndices) throws IOException {
	int numberOfConstructors = 0;
	for (int i = 0; i < numberOfMethodsAndConstructors; i++) {
		stream.skip(2);
		ReferenceIndex referenceIndex = readReferenceIndex(stream);
		methodIndices.add(referenceIndex);
		String constant = (String) constants[referenceIndex.getValue1() - 1].getValue();
		if (constant.contains("<init>")) {
			numberOfConstructors++;
		}
		skipAttributes(stream);
	}
	return numberOfConstructors;
}
 
Example 4
Source File: HollowObjectTypeDataElements.java    From hollow with Apache License 2.0 6 votes vote down vote up
private void readVarLengthData(DataInputStream dis, HollowObjectSchema unfilteredSchema) throws IOException {
    int filteredFieldIdx = 0;

    for(int i=0;i<unfilteredSchema.numFields();i++) {
        long numBytesInVarLengthData = VarInt.readVLong(dis);

        if(schema.getPosition(unfilteredSchema.getFieldName(i)) != -1) {
            if(numBytesInVarLengthData != 0) {
                varLengthData[filteredFieldIdx] = new SegmentedByteArray(memoryRecycler);
                varLengthData[filteredFieldIdx].readFrom(dis, numBytesInVarLengthData);
            }
            filteredFieldIdx++;
        } else {
            while(numBytesInVarLengthData > 0) {
                numBytesInVarLengthData -= dis.skip(numBytesInVarLengthData);
            }
        }
    }
}
 
Example 5
Source File: DataBlockHeaderImpl.java    From pulsar with Apache License 2.0 6 votes vote down vote up
public static DataBlockHeader fromStream(InputStream stream) throws IOException {
    CountingInputStream countingStream = new CountingInputStream(stream);
    DataInputStream dis = new DataInputStream(countingStream);
    int magic = dis.readInt();
    if (magic != MAGIC_WORD) {
        throw new IOException("Data block header magic word not match. read: " + magic + " expected: " + MAGIC_WORD);
    }

    long headerLen = dis.readLong();
    long blockLen = dis.readLong();
    long firstEntryId = dis.readLong();
    long toSkip = headerLen - countingStream.getCount();
    if (dis.skip(toSkip) != toSkip) {
        throw new EOFException("Header was too small");
    }

    return new DataBlockHeaderImpl(headerLen, blockLen, firstEntryId);
}
 
Example 6
Source File: MusReader.java    From mochadoom with GNU General Public License v3.0 6 votes vote down vote up
/** Create a sequence from an InputStream.
 *  This is the counterpart of {@link MidiSystem#getSequence(InputStream)}
 *  for MUS format.
 *
 * @param is MUS data (this method does not try to auto-detect the format.)
 */
public static Sequence getSequence(InputStream is)
throws IOException, InvalidMidiDataException {
    DataInputStream dis = new DataInputStream(is);
    dis.skip(6);
    int rus = dis.readUnsignedShort();
    short scoreStart = Swap.SHORT((char) rus);
    dis.skip(scoreStart - 8);
    Sequence sequence = new Sequence(Sequence.SMPTE_30, 14, 1);
    Track track = sequence.getTracks()[0];
    int[] chanVelocity = new int[16];
    Arrays.fill(chanVelocity, 100);
    EventGroup eg;
    long tick = 0;
    while ((eg = nextEventGroup(dis, chanVelocity)) != null) {
        tick = eg.appendTo(track, tick);
    }
    MetaMessage endOfSequence = new MetaMessage();
    endOfSequence.setMessage(47, new byte[] {0}, 1);
    track.add(new MidiEvent(endOfSequence, tick));
    return sequence;
}
 
Example 7
Source File: ReinterpretDataStreamAsKeyedStreamITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	super.open(parameters);
	int subtaskIdx = getRuntimeContext().getIndexOfThisSubtask();
	File partitionFile = allPartitions.get(subtaskIdx);
	fileLength = partitionFile.length();
	waitForFailurePos = fileLength * 3 / 4;
	din = new DataInputStream(
		new BufferedInputStream(
			new FileInputStream(partitionFile)));

	long toSkip = position;
	while (toSkip > 0L) {
		toSkip -= din.skip(toSkip);
	}
}
 
Example 8
Source File: RealClassBuilder.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
private RealClassField[] readFields(DataInputStream stream) throws IOException {
	RealClassField[] fields = new RealClassField[stream.readUnsignedShort()];
	for (int i = 0; i < fields.length; i++) {
		fields[i] = new RealClassField(stream.readUnsignedShort());
		stream.skip(4);
		skipAttributes(stream);
	}
	return fields;
}
 
Example 9
Source File: HeartbeatBody.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public HeartbeatBody(DataInputStream buffer, long size) throws IOException
{
    if(size > 0)
    {
        //allow other implementations to have a payload, but ignore it:
        buffer.skip(size);
    }
}
 
Example 10
Source File: FixedLengthElementArray.java    From hollow with Apache License 2.0 5 votes vote down vote up
public static void discardFrom(DataInputStream dis) throws IOException {
    long numLongs = VarInt.readVLong(dis);
    long bytesToSkip = numLongs * 8;

    while(bytesToSkip > 0) {
        bytesToSkip -= dis.skip(bytesToSkip);
    }
}
 
Example 11
Source File: RealClassBuilder.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
private RealClassField[] readFields(DataInputStream stream) throws IOException {
	RealClassField[] fields = new RealClassField[stream.readUnsignedShort()];
	for (int i = 0; i < fields.length; i++) {
		fields[i] = new RealClassField(stream.readUnsignedShort());
		stream.skip(4);
		skipAttributes(stream);
	}
	return fields;
}
 
Example 12
Source File: Utils.java    From SigFW with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Avp decodeAvp(byte[] in_b ) throws IOException, AvpDataException {
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(in_b));
    int code = in.readInt();
    int tmp = in.readInt();
    int counter = 0;
    
    int flags = (tmp >> 24) & 0xFF;
    int length = tmp & 0xFFFFFF;
    if (length < 0 || counter + length > in_b.length) {
        throw new AvpDataException("Not enough data in buffer!");
    }
    long vendor = 0;
    boolean hasVendor = false;
    if ((flags & 0x80) != 0) {
        vendor = in.readInt();
        hasVendor = true;
    }
    // Determine body L = length - 4(code) -1(flags) -3(length) [-4(vendor)]
    byte[] rawData = new byte[length - (8 + (hasVendor ? 4 : 0))];
    in.read(rawData);
    // skip remaining.
    // TODO: Do we need to padd everything? Or on send stack should properly fill byte[] ... ?
    if (length % 4 != 0) {
        for (int i; length % 4 != 0; length += i) {
            i = (int) in.skip((4 - length % 4));
        }
    }
    AvpImpl avp = new AvpImpl(code, (short) flags, (int) vendor, rawData);
    return avp;
}
 
Example 13
Source File: HollowBlobReader.java    From hollow with Apache License 2.0 5 votes vote down vote up
private void skipForwardsCompatibilityBytes(DataInputStream is) throws IOException {
    int bytesToSkip = VarInt.readVInt(is);
    while(bytesToSkip > 0) {
        int skippedBytes = (int)is.skip(bytesToSkip);
        if(skippedBytes < 0)
            throw new EOFException();
        bytesToSkip -= skippedBytes;
    }
}
 
Example 14
Source File: DoomSaveGame.java    From mochadoom with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void read(DataInputStream f) throws IOException {
    name=DoomIO.readNullTerminatedString(f,SAVESTRINGSIZE);
    vcheck=DoomIO.readNullTerminatedString(f,VERSIONSIZE);
    String vcheckb= ("version "+VERSION);
    // no more unpacking, and report it.
    if (wrongversion = !(vcheckb.equalsIgnoreCase(vcheck))) return;
    gameskill = f.readByte(); 
    gameepisode = f.readByte();
    gamemap = f.readByte();
    playeringame=new boolean[MAXPLAYERS];
    for (int i=0 ; i<MAXPLAYERS ; i++) 
    playeringame[i] = f.readBoolean(); 

    // load a base level (this doesn't advance the pointer?) 
    //G_InitNew (gameskill, gameepisode, gamemap); 
 
    // get the times 
    int a = f.readUnsignedByte(); 
    int b = f.readUnsignedByte();
    int c =  f.readUnsignedByte();
    // Quite anomalous, leveltime is stored as a BIG ENDIAN, 24-bit unsigned integer :-S
    leveltime = (a<<16) + (b<<8) + c; 

    // Mark this position...
    //long mark=f.getFilePointer();
    //f.seek(f.length()-1);
    //if (f.readByte() != 0x1d) properend=false; else
    //    properend=true;
    //f.seek(mark);
        
    long available=f.available();
    f.skip(available-1);
    if (f.readByte() != 0x1d) properend=false; else
        properend=true;
    
    // We've loaded whatever consistutes "header" info, the rest must be unpacked by proper
    // methods in the game engine itself.
    
}
 
Example 15
Source File: VirtualKeyboard.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
public void readLayout(DataInputStream dis) throws IOException {
	if (dis.readInt() != LAYOUT_SIGNATURE) {
		throw new IOException("file signature not found");
	}
	int version = dis.readInt();
	if (version != LAYOUT_VERSION && version != LAYOUT_OLD_VERSION) {
		throw new IOException("incompatible file version");
	}
	while (true) {
		int block = dis.readInt();
		int length = dis.readInt();
		if (block == LAYOUT_EOF) {
			break;
		}
		int count;
		switch (block) {
			case LAYOUT_KEYS:
				count = dis.readInt();
				int hash;
				boolean found;
				for (int i = 0; i < count; i++) {
					hash = dis.readInt();
					found = false;
					for (int key = 0; key < keypad.length; key++) {
						if (keypad[key].hashCode() == hash) {
							if (version == LAYOUT_VERSION) {
								keypad[key].setVisible(dis.readBoolean());
							}
							snapOrigins[key] = dis.readInt();
							snapModes[key] = dis.readInt();
							snapOffsets[key].x = dis.readFloat();
							snapOffsets[key].y = dis.readFloat();
							found = true;
							break;
						}
					}
					if (!found) {
						dis.skip(16);
					}
				}
				break;
			case LAYOUT_SCALES:
				count = dis.readInt();
				if (count == keyScales.length) {
					for (int i = 0; i < count; i++) {
						keyScales[i] = dis.readFloat();
					}
				} else {
					dis.skip(count * 4);
				}
				break;
			case LAYOUT_COLORS:
				count = dis.readInt();
				if (count == colors.length) {
					for (int i = 0; i < count; i++) {
						colors[i] = dis.readInt();
					}
				} else {
					dis.skip(count * 4);
				}
				break;
			default:
				dis.skip(length);
				break;
		}
	}
}
 
Example 16
Source File: RealClassBuilder.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
private void skipThisClass(DataInputStream stream) throws IOException {
	stream.skip(2);
}
 
Example 17
Source File: GapEncodedVariableLengthIntegerReader.java    From hollow with Apache License 2.0 4 votes vote down vote up
public static void discardEncodedDeltaOrdinals(DataInputStream dis) throws IOException {
    long numBytesToSkip = VarInt.readVLong(dis);
    while(numBytesToSkip > 0) {
        numBytesToSkip -= dis.skip(numBytesToSkip);
    }
}
 
Example 18
Source File: MidiFileReader.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public MidiSequence getSequence(InputStream stream)throws MidiFileException, IOException{
	DataInputStream	in = new DataInputStream(stream);
	if (in.readInt() != HEADER_MAGIC){
		throw new MidiFileException("not a MIDI file: wrong header magic");
	}
	int headerLength = in.readInt();
	if (headerLength < HEADER_LENGTH){
		throw new MidiFileException("corrupt MIDI file: wrong header length");
	}
	int type = in.readShort();
	if (type < 0 || type > 2){
		throw new MidiFileException("corrupt MIDI file: illegal type");
	}
	if (type == 2){
		throw new MidiFileException("this implementation doesn't support type 2 MIDI files");
	}
	int trackCount = in.readShort();
	if (trackCount <= 0){
		throw new MidiFileException("corrupt MIDI file: number of tracks must be positive");
	}
	if (type == 0 && trackCount != 1){
		throw new MidiFileException("corrupt MIDI file:  type 0 files must contain exactely one track");
	}
	float divisionType = -1.0F;
	int resolution = -1;
	int division = in.readUnsignedShort();
	if ((division & 0x8000) != 0){
		int frameType = -((division >>> 8) & 0xFF);
		if(frameType == 24){
			divisionType = MidiSequence.SMPTE_24;
		}else if(frameType == 25){
			divisionType = MidiSequence.SMPTE_25;
		}else if(frameType == 29){
			divisionType = MidiSequence.SMPTE_30DROP;
		}else if(frameType == 30){
			divisionType = MidiSequence.SMPTE_30;
		}else{
			throw new MidiFileException("corrupt MIDI file: illegal frame division type");
		}
		resolution = division & 0xff;
	}else{
		divisionType = MidiSequence.PPQ;
		resolution = division & 0x7fff;
	}
	
	in.skip(headerLength - HEADER_LENGTH);
	
	MidiSequence sequence = new MidiSequence(divisionType,resolution);
	for (int i = 0; i < trackCount; i++){
		MidiTrack track = new MidiTrack();
		sequence.addTrack(track);
		readTrack(in, track);
	}
	
	in.close();
	
	return sequence;
}
 
Example 19
Source File: Geometry.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unused")
public Geometry(InputStream inputStream, long oidToUse) throws IOException {
	DataInputStream dataInputStream = new DataInputStream(inputStream);
	String protocol = dataInputStream.readUTF();
	byte version = dataInputStream.readByte();
	dataInputStream.readFloat();
	dataInputStream.readFloat();
	dataInputStream.readFloat();
	dataInputStream.readFloat();
	dataInputStream.readFloat();
	dataInputStream.readFloat();
	int nrObjects = dataInputStream.readInt();
	int offset = 2;
	for (int i=0; i<nrObjects; i++) {
		String type = dataInputStream.readUTF();
		long oid = dataInputStream.readLong();
		byte geometryType = dataInputStream.readByte();
		
		offset += 3 + type.getBytes("UTF-8").length;
		int skip = 4 - (offset % 4);
		if (skip != 0 && skip != 4) {
			dataInputStream.skip(skip);
		}
		offset = 0;
		
		for (int x=0; x<16; x++) {
			dataInputStream.readFloat();
		}
		if (geometryType == GEOMETRY_TYPE_INSTANCE) {
			dataInputStream.readLong();
		} else if (geometryType == GEOMETRY_TYPE_TRIANGLES) {
			dataInputStream.readLong();
			minX = dataInputStream.readFloat();
			minY = dataInputStream.readFloat();
			minZ = dataInputStream.readFloat();
			maxX = dataInputStream.readFloat();
			maxY = dataInputStream.readFloat();
			maxZ = dataInputStream.readFloat();
			int nrIndices = dataInputStream.readInt();
			IntBuffer indices = readIntBuffer(dataInputStream, nrIndices);
			int nrVertices = dataInputStream.readInt();
			FloatBuffer vertices = readFloatBuffer(dataInputStream, nrVertices);
			int nrNormals = dataInputStream.readInt();
			FloatBuffer normals = readFloatBuffer(dataInputStream, nrNormals);
			int nrMaterials = dataInputStream.readInt();
			FloatBuffer materials = readFloatBuffer(dataInputStream, nrMaterials * 4);
			
			if (oidToUse == oid) {
				this.indices = indices;
				this.vertices = vertices;
				this.normals = normals;
				this.materials = materials;
			}
		}
	}
}
 
Example 20
Source File: RealClassBuilder.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
private void skipThisClass(DataInputStream stream) throws IOException {
	stream.skip(2);
}