public static InputStream streamFile ( final File file , final long offset ) throws IOException { final RandomAccessFile raf = new RandomAccessFile ( file , "r" ) ; final long rafLength = raf . length ( ) ; if ( offset > 0 ) { raf . seek ( offset ) ; } else if ( offset < 0 && offset < rafLength ) { raf . seek ( Math . max ( 0 , rafLength + offset ) ) ; } return Channels . newInputStream ( raf . getChannel ( ) ) ; }
Open a stream to a file .