/** * Read ahead to the infohash, throwing an exception if there isn't enough data. * Also check the first 20 bytes for the correct protocol here and throw IOE if bad, * so we don't hang waiting for 48 bytes if it's not a bittorrent client. * The 20 bytes are checked again in Peer.handshake(). */ private static byte[] readHash(InputStream in) throws IOException { for (int i = 0; i < PROTO_LEN; i++) { int b = in.read(); if (b != PROTO[i]) throw new IOException("Bad protocol 0x" + Integer.toHexString(b) + " at byte " + i); } DataHelper.skip(in, 8); byte buf[] = new byte[20]; int read = DataHelper.read(in, buf); if (read != buf.length) throw new IOException("Unable to read the hash (read " + read + ")"); return buf; }
@Override public void readBytes(InputStream in) throws DataFormatException, IOException { _gateway = Hash.create(in); // flags DataHelper.skip(in, 2); _type = in.read(); _cost = in.read(); _end = new Date(DataHelper.readLong(in, 4) * 1000); }
DataHelper.skip(inputStream, Signature.SIGNATURE_BYTES); byte[] data = new byte[VERSION_BYTES]; int bytesRead = DataHelper.read(inputStream, data);
DataHelper.skip(fileInputStream, Signature.SIGNATURE_BYTES); byte[] data = new byte[VERSION_BYTES]; int bytesRead = DataHelper.read(fileInputStream, data);
fileOutputStream = new FileOutputStream(outputFile); DataHelper.skip(fileInputStream, HEADER_BYTES); DataHelper.copy(fileInputStream, fileOutputStream); } catch (IOException ioe) {
try { if (skip > 0) DataHelper.skip(in, skip); int read = 0; long tot = 0;
@Test public void testSkip() throws Exception { final int sz = 256; TestInputStream tis = new TestInputStream(sz); DataHelper.skip(tis, sz); try { DataHelper.skip(tis, 1); fail(); } catch (IOException ioe) {} DataHelper.skip(tis, 0); try { DataHelper.skip(tis, -1); fail("skipped negative?"); } catch (IllegalArgumentException expected) {} }
in = new FileInputStream(file); if (skip > 0) DataHelper.skip(in, skip); byte[] hdr = new byte[HEADER_LEN]; DataHelper.read(in, hdr); if (!DataHelper.eq(hdr, magicStart)) throw new ZipException("Not a zip file: " + file); DataHelper.skip(in, fileLen - (skip + HEADER_LEN + buffer.length)); DataHelper.read(in, buffer); return getComment(buffer);
throw new IOException("Not a IPv6 geoip data file"); DataHelper.skip(in, HEADER_LEN - MAGIC.length()); byte[] buf = new byte[18]; while (idx < search.length) {
DataHelper.skip(in, 32);