Exemplo n.º 1
0
 @Override
 public InputStream createInputStream() throws IOException {
   FileInputStream is = null;
   try {
     is = new FileInputStream(file);
     ByteStreams.skipFully(is, offset);
     return new LimitedInputStream(is, length);
   } catch (IOException e) {
     try {
       if (is != null) {
         long size = file.length();
         throw new IOException(
             "Error in reading " + this + " (actual file length " + size + ")", e);
       }
     } catch (IOException ignored) {
       // ignore
     } finally {
       JavaUtils.closeQuietly(is);
     }
     throw new IOException("Error in opening " + this, e);
   } catch (RuntimeException e) {
     JavaUtils.closeQuietly(is);
     throw e;
   }
 }
Exemplo n.º 2
0
 protected Payload doSlice(InputStream content, long offset, long length) {
   try {
     ByteStreams.skipFully(content, offset);
   } catch (IOException ioe) {
     throw Throwables.propagate(ioe);
   }
   return new InputStreamPayload(ByteStreams.limit(content, length));
 }
Exemplo n.º 3
0
 private InputStream sliceStream(InputStream in) throws IOException {
   if (offset > 0) {
     try {
       ByteStreams.skipFully(in, offset);
     } catch (Throwable e) {
       Closer closer = Closer.create();
       closer.register(in);
       try {
         throw closer.rethrow(e);
       } finally {
         closer.close();
       }
     }
   }
   return ByteStreams.limit(in, length);
 }