List of usage examples for java.io DataInput skipBytes
int skipBytes(int n) throws IOException;
From source file:RandomFileTest.java
public static String readFixedString(int size, DataInput dataInput) throws IOException { StringBuffer strBuffer = new StringBuffer(size); int count = 0; boolean more = true; while (more && count < size) { char aChar = dataInput.readChar(); count++;/*w w w . j a v a2s.c o m*/ if (aChar == 0) more = false; else strBuffer.append(aChar); } dataInput.skipBytes(2 * (size - count)); return strBuffer.toString(); }
From source file:RandomFileTest.java
public static String readFixedString(int size, DataInput in) throws IOException { StringBuilder b = new StringBuilder(size); int i = 0;//from ww w .j a va 2s.c om boolean more = true; while (more && i < size) { char ch = in.readChar(); i++; if (ch == 0) more = false; else b.append(ch); } in.skipBytes(2 * (size - i)); return b.toString(); }
From source file:com.icloud.framework.core.util.FBUtilities.java
/** @return null */ public static byte[] skipShortByteArray(DataInput in) throws IOException { int skip = readShortLength(in); while (skip > 0) { int skipped = in.skipBytes(skip); if (skipped == 0) throw new EOFException(); skip -= skipped;//from w w w.j a v a 2 s . com } return null; }
From source file:com.martinkampjensen.thesis.util.gromacs.EnergyExtractor.java
/** * Skips over <code>n</code> bytes of data from the input stream, discarding * the skipped bytes.//from w ww .j ava 2s . c om * * @param input the stream in which to skip bytes. * @param n the number of bytes to be skipped. * @throws IOException if an I/O error occurs. * @see DataInput#skipBytes(int) */ private static void skipBytes(DataInput input, int n) throws IOException { while (n > 0) { n -= input.skipBytes(n); } }
From source file:jadx.core.utils.android.Res9patchStreamDecoder.java
private void find9patchChunk(DataInput di) throws JadxException, IOException { di.skipBytes(8); while (true) { int size; try {/*from w ww .j a v a 2 s .co m*/ size = di.readInt(); } catch (IOException ex) { throw new JadxException("Cant find nine patch chunk", ex); } if (di.readInt() == NP_CHUNK_TYPE) { return; } di.skipBytes(size + 4); } }
From source file:brut.androlib.res.decoder.Res9patchStreamDecoder.java
private void find9patchChunk(DataInput di) throws AndrolibException, IOException { di.skipBytes(8); while (true) { int size; try {//from ww w . j a va 2 s. c o m size = di.readInt(); } catch (IOException ex) { throw new CantFind9PatchChunk("Cant find nine patch chunk", ex); } if (di.readInt() == NP_CHUNK_TYPE) { return; } di.skipBytes(size + 4); } }
From source file:bobs.is.compress.sevenzip.SevenZFile.java
private static long skipBytesFully(final DataInput input, long bytesToSkip) throws IOException { if (bytesToSkip < 1) { return 0; }/*from w ww . j a v a2s .co m*/ long skipped = 0; while (bytesToSkip > Integer.MAX_VALUE) { final long skippedNow = skipBytesFully(input, Integer.MAX_VALUE); if (skippedNow == 0) { return skipped; } skipped += skippedNow; bytesToSkip -= skippedNow; } while (bytesToSkip > 0) { final int skippedNow = input.skipBytes((int) bytesToSkip); if (skippedNow == 0) { return skipped; } skipped += skippedNow; bytesToSkip -= skippedNow; } return skipped; }
From source file:edu.umn.cs.spatialHadoop.core.RTree.java
/** * Reads and skips the header of the tree returning the total number of * bytes skipped from the stream. This is used as a preparatory function to * read all elements in the tree without the index part. * @param in// w w w . j ava2 s .co m * @return - Total number of bytes read and skipped * @throws IOException */ public static int skipHeader(InputStream in) throws IOException { DataInput dataIn = in instanceof DataInput ? (DataInput) in : new DataInputStream(in); int skippedBytes = 0; /*int treeSize = */dataIn.readInt(); skippedBytes += 4; int height = dataIn.readInt(); skippedBytes += 4; if (height == 0) { // Empty tree. No results return skippedBytes; } int degree = dataIn.readInt(); skippedBytes += 4; int nodeCount = (int) ((powInt(degree, height) - 1) / (degree - 1)); /*int elementCount = */dataIn.readInt(); skippedBytes += 4; // Skip all nodes dataIn.skipBytes(nodeCount * NodeSize); skippedBytes += nodeCount * NodeSize; return skippedBytes; }
From source file:com.ricemap.spateDB.core.RTree.java
/** * Reads and skips the header of the tree returning the total number of * bytes skipped from the stream. This is used as a preparatory function to * read all elements in the tree without the index part. * //from w ww. ja va 2s .c om * @param in * @return - Total number of bytes read and skipped * @throws IOException */ public static int skipHeader(InputStream in) throws IOException { DataInput dataIn = in instanceof DataInput ? (DataInput) in : new DataInputStream(in); int skippedBytes = 0; /* int treeSize = */dataIn.readInt(); skippedBytes += 4; int height = dataIn.readInt(); skippedBytes += 4; if (height == 0) { // Empty tree. No results return skippedBytes; } int degree = dataIn.readInt(); skippedBytes += 4; int nodeCount = (int) ((powInt(degree, height) - 1) / (degree - 1)); /* int elementCount = */dataIn.readInt(); skippedBytes += 4; // Skip all nodes dataIn.skipBytes(nodeCount * NodeSize); skippedBytes += nodeCount * NodeSize; return skippedBytes; }
From source file:edu.msu.cme.rdp.readseq.readers.core.SFFCore.java
public ReadBlock readReadBlock() throws IOException { try {// w w w .ja v a 2s . co m DataInput seqFile = super.getDataInput(); ReadBlock ret = new ReadBlock(); /* * READ BLOCK HEADER */ ret.headerLength = seqFile.readShort(); ret.nameLength = seqFile.readShort(); int tmp = (ret.headerLength << 16) | ret.nameLength; if (tmp == mftMagicNumber) { //We ended up in the index...certainly possible return null; } ret.numBases = seqFile.readInt(); ret.clipQualLeft = seqFile.readUnsignedShort(); ret.clipQualRight = seqFile.readUnsignedShort(); ret.clipAdapterLeft = seqFile.readUnsignedShort(); ret.clipAdapterRight = seqFile.readUnsignedShort(); byte[] readName = new byte[ret.nameLength]; super.read(readName); int dataOffset = ret.headerLength - (ret.nameLength + READ_BLOCK_STATIC_SIZE); if (dataOffset < 0) { throw new IOException("Illegal ReadBlock header length (" + ret.headerLength + "), it would have me seek back in to the readblock"); } seqFile.skipBytes(dataOffset); /* * READ BLOCK DATA */ byte[] flowgramIndex = new byte[ret.numBases]; byte[] bases = new byte[ret.numBases]; byte[] quality = new byte[ret.numBases]; byte[] homopolymerStretchEstimates = new byte[(commonHeader.flowLength) * 2]; super.read(homopolymerStretchEstimates); super.read(flowgramIndex); super.read(bases); super.read(quality); DataInputStream flowgramStream = new DataInputStream( new ByteArrayInputStream(homopolymerStretchEstimates)); short[] flowgrams = new short[commonHeader.flowLength]; for (int index = 0; index < commonHeader.flowLength; index++) { flowgrams[index] = flowgramStream.readShort(); } flowgramStream.close(); ret.name = new String(readName); ret.flowgrams = flowgrams; ret.flowIndex = flowgramIndex; ret.seq = new String(bases); ret.qual = quality; int bytesRead = homopolymerStretchEstimates.length + flowgramIndex.length + bases.length + quality.length; alignToBoundary(bytesRead); return ret; } catch (EOFException e) { return null; } }