/** * Skips the requested number of characters or fail if there are not enough left. * <p> * This allows for the possibility that {@link Reader#skip(long)} may * not skip as many characters as requested (most likely because of reaching EOF). * <p> * Note that the implementation uses {@link #skip(Reader, long)}. * This means that the method may be considerably less efficient than using the actual skip implementation, * this is done to guarantee that the correct number of characters are skipped. * </p> * * @param input stream to skip * @param toSkip the number of characters to skip * @throws IOException if there is a problem reading the file * @throws IllegalArgumentException if toSkip is negative * @throws EOFException if the number of characters skipped was incorrect * @see Reader#skip(long) * @since 2.0 */ public static void skipFully(final Reader input, final long toSkip) throws IOException { final long skipped = skip(input, toSkip); if (skipped != toSkip) { throw new EOFException("Chars to skip: " + toSkip + " actual: " + skipped); } }
/** * Skips the requested number of bytes or fail if there are not enough left. * * @param input ReadableByteChannel to skip * @param toSkip the number of bytes to skip * @throws IOException if there is a problem reading the ReadableByteChannel * @throws IllegalArgumentException if toSkip is negative * @throws EOFException if the number of bytes skipped was incorrect * @since 2.5 */ public static void skipFully(final ReadableByteChannel input, final long toSkip) throws IOException { if (toSkip < 0) { throw new IllegalArgumentException("Bytes to skip must not be negative: " + toSkip); } final long skipped = skip(input, toSkip); if (skipped != toSkip) { throw new EOFException("Bytes to skip: " + toSkip + " actual: " + skipped); } }
/** * Skips the requested number of bytes or fail if there are not enough left. * <p> * This allows for the possibility that {@link InputStream#skip(long)} may * not skip as many bytes as requested (most likely because of reaching EOF). * <p> * Note that the implementation uses {@link #skip(InputStream, long)}. * This means that the method may be considerably less efficient than using the actual skip implementation, * this is done to guarantee that the correct number of characters are skipped. * </p> * * @param input stream to skip * @param toSkip the number of bytes to skip * @throws IOException if there is a problem reading the file * @throws IllegalArgumentException if toSkip is negative * @throws EOFException if the number of bytes skipped was incorrect * @see InputStream#skip(long) * @since 2.0 */ public static void skipFully(final InputStream input, final long toSkip) throws IOException { if (toSkip < 0) { throw new IllegalArgumentException("Bytes to skip must not be negative: " + toSkip); } final long skipped = skip(input, toSkip); if (skipped != toSkip) { throw new EOFException("Bytes to skip: " + toSkip + " actual: " + skipped); } }
private long computeClassPathHash(final URL... classpathEntry) { final Adler32 adler32 = new Adler32(); for (final URL url : classpathEntry) { try (CheckedInputStream inputStream = new CheckedInputStream(url.openStream(), adler32)) { // Just read it, the CheckedInputStream will update the checksum on it's own while (IOUtils.skip(inputStream, Long.MAX_VALUE) == Long.MAX_VALUE) { // just loop } } catch (final FileNotFoundException ignored) { LOG.warning("Auxclasspath entry " + url.toString() + " doesn't exist, ignoring it"); } catch (final IOException e) { // Can this even happen? LOG.log(Level.SEVERE, "Incremental analysis can't check auxclasspath contents", e); throw new RuntimeException(e); } } return adler32.getValue(); }
@Test public void testSkip_ReadableByteChannel() throws Exception { final FileInputStream fileInputStream = new FileInputStream(m_testFile); final FileChannel fileChannel = fileInputStream.getChannel(); try { assertEquals(FILE_SIZE - 10, IOUtils.skip(fileChannel, FILE_SIZE - 10)); assertEquals(10, IOUtils.skip(fileChannel, 20)); assertEquals(0, IOUtils.skip(fileChannel, 10)); } finally { IOUtils.closeQuietly(fileChannel, fileInputStream); } }
} else { try (InputStream logInputStream = run.getLogInputStream()) { IOUtils.skip(logInputStream, pos); IOUtils.copy(new InputStreamReader(logInputStream, run.getCharset()), w);
@Override public long skip(final long len) throws IOException { return IOUtils.skip(this, len); } }
@Override public long skip(final long len) throws IOException { return IOUtils.skip(this, len); }
/** * Fully skips the specified size from the given input stream. * * <p> * {@link InputStream#skip(long)} has two problems. One is that * it doesn't let us reliably differentiate "hit EOF" case vs "inpustream just returning 0 since there's no data * currently available at hand", and some subtypes (such as {@link FileInputStream#skip(long)} returning -1. * * <p> * So to reliably skip just the N bytes, we'll actually read all those bytes. * * @since 1.349 * @deprecated use {@link org.apache.commons.io.IOUtils#skip(java.io.InputStream, long)} instead * @since 2.1.2 */ public static long skip(InputStream in, long size) throws IOException { return org.apache.commons.io.IOUtils.skip(in, size); }
/** * Fully skips the specified size from the given input stream. * * <p> * {@link InputStream#skip(long)} has two problems. One is that * it doesn't let us reliably differentiate "hit EOF" case vs "inpustream just returning 0 since there's no data * currently available at hand", and some subtypes (such as {@link FileInputStream#skip(long)} returning -1. * * <p> * So to reliably skip just the N bytes, we'll actually read all those bytes. * * @since 1.349 * @deprecated use {@link org.apache.commons.io.IOUtils#skip(java.io.InputStream, long)} instead * @since 2.1.2 */ public static long skip(InputStream in, long size) throws IOException { return org.apache.commons.io.IOUtils.skip(in, size); }
/** * Fully skips the specified size from the given input stream. * * <p> * {@link InputStream#skip(long)} has two problems. One is that * it doesn't let us reliably differentiate "hit EOF" case vs "inpustream just returning 0 since there's no data * currently available at hand", and some subtypes (such as {@link FileInputStream#skip(long)} returning -1. * * <p> * So to reliably skip just the N bytes, we'll actually read all those bytes. * * @since 1.349 * @deprecated use {@link org.apache.commons.io.IOUtils#skip(java.io.InputStream, long)} instead * @since 2.1.2 */ public static long skip(InputStream in, long size) throws IOException { return org.apache.commons.io.IOUtils.skip(in, size); }
/** * Fully skips the specified size from the given input stream. * * <p> {@link InputStream#skip(long)} has two problems. One is that it * doesn't let us reliably differentiate "hit EOF" case vs "inpustream just * returning 0 since there's no data currently available at hand", and some * subtypes (such as {@link FileInputStream#skip(long)} returning -1. * * <p> So to reliably skip just the N bytes, we'll actually read all those * bytes. * * @since 1.349 * @deprecated use * {@link org.apache.commons.io.IOUtils#skip(java.io.InputStream, long)} * instead * @since 2.1.2 */ public static long skip(InputStream in, long size) throws IOException { return org.apache.commons.io.IOUtils.skip(in, size); }
/** * Skips the requested number of bytes or fail if there are not enough left. * * @param input ReadableByteChannel to skip * @param toSkip the number of bytes to skip * @throws IOException if there is a problem reading the ReadableByteChannel * @throws IllegalArgumentException if toSkip is negative * @throws EOFException if the number of bytes skipped was incorrect * @since 2.5 */ public static void skipFully(final ReadableByteChannel input, final long toSkip) throws IOException { if (toSkip < 0) { throw new IllegalArgumentException("Bytes to skip must not be negative: " + toSkip); } final long skipped = skip(input, toSkip); if (skipped != toSkip) { throw new EOFException("Bytes to skip: " + toSkip + " actual: " + skipped); } }
/** * Skips the requested number of bytes or fail if there are not enough left. * * @param input ReadableByteChannel to skip * @param toSkip the number of bytes to skip * @throws IOException if there is a problem reading the ReadableByteChannel * @throws IllegalArgumentException if toSkip is negative * @throws EOFException if the number of bytes skipped was incorrect * @since 2.5 */ public static void skipFully(final ReadableByteChannel input, final long toSkip) throws IOException { if (toSkip < 0) { throw new IllegalArgumentException("Bytes to skip must not be negative: " + toSkip); } final long skipped = skip(input, toSkip); if (skipped != toSkip) { throw new EOFException("Bytes to skip: " + toSkip + " actual: " + skipped); } }
private long computeClassPathHash(final URL... classpathEntry) { final Adler32 adler32 = new Adler32(); for (final URL url : classpathEntry) { try (CheckedInputStream inputStream = new CheckedInputStream(url.openStream(), adler32)) { // Just read it, the CheckedInputStream will update the checksum on it's own while (IOUtils.skip(inputStream, Long.MAX_VALUE) == Long.MAX_VALUE) { // just loop } } catch (final FileNotFoundException ignored) { LOG.warning("Auxclasspath entry " + url.toString() + " doesn't exist, ignoring it"); } catch (final IOException e) { // Can this even happen? LOG.log(Level.SEVERE, "Incremental analysis can't check auxclasspath contents", e); throw new RuntimeException(e); } } return adler32.getValue(); }
private void skipToTail(InputStream input) throws IOException { long toSkip = logFile.length() - tailSize; if (tailSize > 0 && toSkip > 0) { long skipped = IOUtils.skip(input, toSkip); if (skipped < toSkip) { log.warn("Could not skip the requested amount of bytes " + tailSize + " for file " + logFile.getName() + " only skipped " + skipped + " bytes."); } } } }
private long getFileSize(String file) throws IOException { try (InputStream is = GeoJsonSplitterTest.class.getResourceAsStream(file)) { return IOUtils.skip(is, Long.MAX_VALUE); } }
public static long skip(ActionContext actionContext) throws IOException { Thing self = actionContext.getObject("self"); Object input = self.doAction("getInput", actionContext); Long skipSize = (Long) self.doAction("getSkipSize", actionContext); if(input instanceof InputStream){ return IOUtils.skip((InputStream) input, skipSize); }else if(input instanceof Reader){ return IOUtils.skip((Reader) input, skipSize); }else if(input instanceof ReadableByteChannel){ return IOUtils.skip((ReadableByteChannel) input, skipSize); }else{ throw new ActionException("Unsupport input " + input + ", action=" + self.getMetadata().getPath()); } }