Example usage for java.io FileInputStream skip

List of usage examples for java.io FileInputStream skip

Introduction

In this page you can find the example usage for java.io FileInputStream skip.

Prototype

public long skip(long n) throws IOException 

Source Link

Document

Skips over and discards n bytes of data from the input stream.

Usage

From source file:org.carbondata.core.datastorage.store.impl.FileFactory.java

/**
 * return the datainputStream which is seek to the offset of file
 *
 * @param path//w w  w .ja v a2 s .  c  om
 * @param fileType
 * @param bufferSize
 * @param offset
 * @return DataInputStream
 * @throws IOException
 */
public static DataInputStream getDataInputStream(String path, FileType fileType, int bufferSize, long offset)
        throws IOException {
    path = path.replace("\\", "/");
    switch (fileType) {
    case HDFS:
    case VIEWFS:
        Path pt = new Path(path);
        FileSystem fs = pt.getFileSystem(configuration);
        FSDataInputStream stream = fs.open(pt, bufferSize);
        stream.seek(offset);
        return new DataInputStream(new BufferedInputStream(stream));
    default:
        FileInputStream fis = new FileInputStream(path);
        long actualSkipSize = 0;
        long skipSize = offset;
        while (actualSkipSize != offset) {
            actualSkipSize += fis.skip(skipSize);
            skipSize = skipSize - actualSkipSize;
        }
        return new DataInputStream(new BufferedInputStream(fis));
    }
}

From source file:thv.th.reader.SavegameReader.java

private static void readObjectInfo(FileInputStream saveStream, Tile tile, FileInputStream frameStream,
        FileInputStream listStream, FileInputStream elementStream, File tabFile, File chunksFile,
        THPalette palette) throws IOException {
    if (tile.getAnim() != 0) {
        int base = 131085 + tile.getAnim() * 175;
        ObjectInfo oi = new ObjectInfo(base);

        saveStream.getChannel().position(8 + base);
        int frameIndex = EndianUtils.readSwappedShort(saveStream);

        saveStream.skip(6);
        int byte16 = saveStream.read();

        saveStream.getChannel().position(base + 29);
        oi.setLayerId(saveStream.read(), 0);
        oi.setLayerId(saveStream.read(), 1);
        oi.setLayerId(saveStream.read(), 2);
        oi.setLayerId(saveStream.read(), 3);
        oi.setLayerId(saveStream.read(), 4);
        oi.setLayerId(saveStream.read(), 5);
        oi.setLayerId(saveStream.read(), 6);
        oi.setLayerId(saveStream.read(), 7);
        oi.setLayerId(saveStream.read(), 8);
        oi.setLayerId(saveStream.read(), 9);
        oi.setLayerId(saveStream.read(), 10);
        oi.setLayerId(saveStream.read(), 11);
        oi.setLayerId(saveStream.read(), 12);

        THFrame frame = FramesReader.readByIndex(frameIndex, frameStream, listStream, elementStream, tabFile,
                chunksFile, palette);/*w w  w . ja va2 s  .c om*/

        oi.setFrame(frame);
        oi.setByte16(byte16);

        tile.setObjectInfo(oi);
    }
}

From source file:org.apache.carbondata.core.datastore.impl.FileFactory.java

/**
 * return the datainputStream which is seek to the offset of file
 *
 * @param path//from   www  .  j  a  v  a  2 s. co m
 * @param fileType
 * @param bufferSize
 * @param offset
 * @return DataInputStream
 * @throws IOException
 */
public static DataInputStream getDataInputStream(String path, FileType fileType, int bufferSize, long offset)
        throws IOException {
    path = path.replace("\\", "/");
    switch (fileType) {
    case HDFS:
    case ALLUXIO:
    case VIEWFS:
        Path pt = new Path(path);
        FileSystem fs = pt.getFileSystem(configuration);
        FSDataInputStream stream = fs.open(pt, bufferSize);
        stream.seek(offset);
        return new DataInputStream(new BufferedInputStream(stream));
    default:
        path = getUpdatedFilePath(path, fileType);
        FileInputStream fis = new FileInputStream(path);
        long actualSkipSize = 0;
        long skipSize = offset;
        while (actualSkipSize != offset) {
            actualSkipSize += fis.skip(skipSize);
            skipSize = skipSize - actualSkipSize;
        }
        return new DataInputStream(new BufferedInputStream(fis));
    }
}

From source file:org.apache.carbondata.core.datastorage.store.impl.FileFactory.java

/**
 * return the datainputStream which is seek to the offset of file
 *
 * @param path/*from   www  . ja va 2 s  .  c o  m*/
 * @param fileType
 * @param bufferSize
 * @param offset
 * @return DataInputStream
 * @throws IOException
 */
public static DataInputStream getDataInputStream(String path, FileType fileType, int bufferSize, long offset)
        throws IOException {
    path = path.replace("\\", "/");
    switch (fileType) {
    case HDFS:
    case ALLUXIO:
    case VIEWFS:
        Path pt = new Path(path);
        FileSystem fs = pt.getFileSystem(configuration);
        FSDataInputStream stream = fs.open(pt, bufferSize);
        stream.seek(offset);
        return new DataInputStream(new BufferedInputStream(stream));
    default:
        FileInputStream fis = new FileInputStream(path);
        long actualSkipSize = 0;
        long skipSize = offset;
        while (actualSkipSize != offset) {
            actualSkipSize += fis.skip(skipSize);
            skipSize = skipSize - actualSkipSize;
        }
        return new DataInputStream(new BufferedInputStream(fis));
    }
}

From source file:com.oneis.appserver.FileResponse.java

public void writeRangeToOutputStream(OutputStream stream, long offset, long length) throws IOException {
    if (length == 0) {
        return;/*w  ww  .j  a v a  2s. c  om*/
    }
    FileInputStream in = new FileInputStream(file);
    try {
        in.skip(offset);
        byte[] buffer = new byte[4096];
        long count = 0;
        int n = 0;
        while (count < length && (-1 != (n = in.read(buffer, 0,
                (int) (((length - count) > 4096) ? 4096 : (length - count)))))) {
            stream.write(buffer, 0, n);
            count += n;
        }
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.geowebcache.arcgis.compact.BundleFileResource.java

/** @see org.geowebcache.io.Resource#getInputStream() */
public InputStream getInputStream() throws IOException {
    FileInputStream fis = new FileInputStream(bundleFilePath);
    long skipped = fis.skip(tileOffset);
    if (skipped != tileOffset) {
        log.error("tried to skip to tile offset " + tileOffset + " in " + bundleFilePath + " but skipped "
                + skipped + " instead.");
    }//w  ww  .  j  a  v  a  2 s . co  m
    return fis;
}

From source file:org.sakaiproject.nakamura.docproxy.disk.DiskDocumentResult.java

/**
 * /*from w ww. j  av  a2s  .c  o  m*/
 * {@inheritDoc}
 * 
 * @see org.sakaiproject.nakamura.api.docproxy.ExternalDocumentResult#getDocumentInputStream(long)
 */
public InputStream getDocumentInputStream(long startingAt, String userId) throws DocProxyException {
    FileInputStream in = null;
    try {
        in = new FileInputStream(file);
        in.skip(startingAt);
        return in;
    } catch (FileNotFoundException e) {
        return null;
    } catch (IOException e) {
        try {
            in.close();
        } catch (IOException e1) {
            return null;
        }
        return null;
    }
}

From source file:io.druid.data.input.impl.prefetch.RetryingInputStreamTest.java

@Before
public void setup() throws IOException {
    testFile = temporaryFolder.newFile();

    try (FileOutputStream fis = new FileOutputStream(testFile);
            GZIPOutputStream gis = new GZIPOutputStream(fis);
            DataOutputStream dis = new DataOutputStream(gis)) {
        for (int i = 0; i < 10000; i++) {
            dis.writeInt(i);/*from ww  w. j  a  v a  2s. com*/
        }
    }

    throwError = false;

    final InputStream retryingInputStream = new RetryingInputStream<>(testFile, new ObjectOpenFunction<File>() {
        @Override
        public InputStream open(File object) throws IOException {
            return new TestInputStream(new FileInputStream(object));
        }

        @Override
        public InputStream open(File object, long start) throws IOException {
            final FileInputStream fis = new FileInputStream(object);
            Preconditions.checkState(fis.skip(start) == start);
            return new TestInputStream(fis);
        }
    }, e -> e instanceof IOException, MAX_RETRY);

    inputStream = new DataInputStream(new GZIPInputStream(retryingInputStream));

    throwError = true;
}

From source file:com.guye.baffle.decoder.ArscData.java

public CRC32 createObfuscateFile(StringBlock tableBlock, StringBlock keyBlock, File file) throws IOException {
    FileOutputStream fileOutputStream = new FileOutputStream(file);
    CRC32 cksum = new CRC32();
    CheckedOutputStream checkedOutputStream = new CheckedOutputStream(fileOutputStream, cksum);
    LEDataOutputStream out = new LEDataOutputStream(checkedOutputStream);

    int tableStrChange = getmTableStrings().getSize() - tableBlock.getSize();
    int keyStrChange = getmSpecNames().getSize() - keyBlock.getSize();
    getmHeader().chunkSize -= (tableStrChange + keyStrChange);
    getmHeader().write(out);//  w  w w. jav a 2  s  . c o  m
    out.writeInt(1);
    tableBlock.write(out);
    getmPkgHeader().header.chunkSize -= keyStrChange;
    getmPkgHeader().write(out);
    getTypeNames().write(out);
    keyBlock.write(out);

    byte[] buff = new byte[1024];
    FileInputStream in = new FileInputStream(getFile());
    in.skip(getmResIndex());
    int len;
    while (((len = in.read(buff)) != -1)) {
        out.write(buff, 0, len);
    }

    in.close();
    out.close();
    checkedOutputStream.close();
    fileOutputStream.close();
    return cksum;
}

From source file:org.neo4j.qa.driver.WindowsCommunityDriver.java

private String readInstallationLog(String path) {
    try {/*  w ww  .  ja  v  a2s  .c o m*/
        int c;
        File f = File.createTempFile("install", "log");

        vm.copyFromVM(path, f.getAbsolutePath());

        FileInputStream in = new FileInputStream(f);
        StringBuilder b = new StringBuilder();

        in.skip(2); // Windows puts "FF FE" at the beginning of the file.

        while ((c = in.read()) != -1) {
            b.append((char) c);
            in.skip(1); // Every other byte is null
        }
        return b.toString();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}