List of usage examples for java.io InputStream skip
public long skip(long n) throws IOException
n
bytes of data from this input stream. From source file:org.mycore.common.content.util.MCRServletContentHelper.java
public static long copyLarge(InputStream input, OutputStream output, long inputOffset, long length, byte[] buffer) throws IOException { if (inputOffset > 0L) { long bytesToSkip = inputOffset; while (bytesToSkip > 0) { bytesToSkip -= input.skip(bytesToSkip); }//from w ww. j a v a 2 s .c om } if (length == 0L) { return 0L; } else { int bufferLength = buffer.length; int bytesToRead = bufferLength; if (length > 0L && length < (long) bufferLength) { bytesToRead = (int) length; } long totalRead = 0L; int read; while (bytesToRead > 0 && -1 != (read = input.read(buffer, 0, bytesToRead))) { output.write(buffer, 0, read); totalRead += (long) read; if (length > 0L) { bytesToRead = (int) Math.min(length - totalRead, (long) bufferLength); } } return totalRead; } }
From source file:com.adobe.communities.ugc.migration.importer.BufferedBase64DecoderStream.java
public BufferedBase64DecoderStream(final long offset, final InputStream inputStream) throws IOException { inputStream.skip(offset); this.inputStream = inputStream; writeBuffer = new char[WRITE_BUFFER_SIZE]; readToBuffer();// w ww. j a v a 2s .co m }
From source file:be.fedict.eid.applet.service.signer.odf.ODFSignatureFacet.java
/** * Unfortunately zipEntry.getSize() often returns -1/size unknown, so this * is a quick hack to see if the file is empty or not * //ww w . ja va 2s. c o m * @param inputStream * @return * @throws IOException */ private boolean isEmpty(InputStream inputStream) throws IOException { return 0 == inputStream.skip(1); }
From source file:org.sakaiproject.nakamura.docproxy.AbstractDocumentResult.java
/** * {@inheritDoc}//from w w w. j a va 2 s. com * @see org.sakaiproject.nakamura.api.docproxy.ExternalDocumentResult#getDocumentInputStream(long, java.lang.String) */ @Override public InputStream getDocumentInputStream(long startingAt, String userId) throws DocProxyException { InputStream is = getDocumentInputStream(userId); if (is != null) { try { long skipped = is.skip(startingAt); if (skipped < startingAt) { LOGGER.warn("Skipped less bytes than requested. Requested {}, actual {}.", startingAt, skipped); } } catch (IOException e) { IOUtils.closeQuietly(is); return null; } } return is; }
From source file:io.druid.segment.realtime.firehose.HttpFirehoseFactory.java
@Override protected InputStream openObjectStream(URI object, long start) throws IOException { if (supportContentRange) { final URLConnection connection = object.toURL().openConnection(); // Set header for range request. // Since we need to set only the start offset, the header is "bytes=<range-start>-". // See https://tools.ietf.org/html/rfc7233#section-2.1 connection.addRequestProperty(HttpHeaders.RANGE, StringUtils.format("bytes=%d-", start)); return connection.getInputStream(); } else {//from w w w . ja v a 2s. c o m log.warn( "Since the input source doesn't support range requests, the object input stream is opened from the start and " + "then skipped. This may make the ingestion speed slower. Consider enabling prefetch if you see this message" + " a lot."); final InputStream in = openObjectStream(object); in.skip(start); return in; } }
From source file:net.yacy.kelondro.util.FileUtils.java
/** * Copies a part of a File to an OutputStream. * Important : it is the responsibility of the caller to close the destination stream. * @param source File instance/*w ww . j ava 2 s . c om*/ * @param dest OutputStream instance * @param start Number of bytes to skip from the beginning of the File * @throws IOException when a read/write error occurred * @throws NullPointerException when a parameter is null * @throws IllegalStateException when an error occurred while skipping bytes * @see #copy(InputStream source, OutputStream dest) * @see #copy(InputStream source, File dest) * @see #copy(File source, OutputStream dest) * @see #copy(File source, File dest) */ public static void copyRange(final File source, final OutputStream dest, final int start) throws IOException { InputStream fis = null; try { fis = new FileInputStream(source); final long skipped = fis.skip(start); if (skipped != start) { throw new IllegalStateException( "Unable to skip '" + start + "' bytes. Only '" + skipped + "' bytes skipped."); } copy(fis, dest, -1); } finally { if (fis != null) { try { fis.close(); } catch (final Exception e) { } } } }
From source file:org.apache.jackrabbit.core.value.BLOBFileValue.java
/** * {@inheritDoc}/*from w w w. j ava 2 s. c o m*/ */ public int read(byte[] b, long position) throws IOException, RepositoryException { InputStream in = getStream(); in.skip(position); return in.read(b); }
From source file:org.apache.spark.io.GenericFileInputStreamSuite.java
@Test public void testBytesSkipped() throws IOException { for (InputStream inputStream : inputStreams) { assertEquals(1024, inputStream.skip(1024)); for (int i = 1024; i < randomBytes.length; i++) { assertEquals(randomBytes[i], (byte) inputStream.read()); }//w ww .j ava 2 s .c o m } }
From source file:org.apache.spark.io.GenericFileInputStreamSuite.java
@Test public void testBytesSkippedAfterEOF() throws IOException { for (InputStream inputStream : inputStreams) { assertEquals(randomBytes.length, inputStream.skip(randomBytes.length + 1)); assertEquals(-1, inputStream.read()); }/* ww w . j a v a 2 s . c om*/ }
From source file:org.apache.spark.io.NioBufferedFileInputStreamSuite.java
@Test public void testBytesSkipped() throws IOException { InputStream inputStream = new NioBufferedFileInputStream(inputFile); assertEquals(1024, inputStream.skip(1024)); for (int i = 1024; i < randomBytes.length; i++) { assertEquals(randomBytes[i], (byte) inputStream.read()); }/* ww w . ja v a 2s . c o m*/ }