All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.archive.util.binsearch.impl.RandomAccessFileSeekableLineReader Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package org.archive.util.binsearch.impl;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;

import org.archive.util.binsearch.AbstractSeekableLineReader;

import com.google.common.io.LimitInputStream;

public class RandomAccessFileSeekableLineReader extends AbstractSeekableLineReader {
	
	private RandomAccessFile raf;

	public RandomAccessFileSeekableLineReader(RandomAccessFile raf, int blockSize) {
		super(blockSize);
		this.raf = raf;
	}

	public InputStream doSeekLoad(long offset, int maxLength) throws IOException {
		raf.seek(offset);
		
    	FileInputStream fis = new FileInputStream(raf.getFD());
    	
    	if (maxLength > 0) {
    		return new LimitInputStream(fis, maxLength);
    	} else {
    		return fis;
    	}
    }
		
	public long getOffset() throws IOException
	{
		if (closed) {
			return 0;
		}
		
		return raf.getFilePointer();
	}
	
	public void doClose() throws IOException {
		if (raf != null) {
			raf.close();
		}
		raf = null;
	}
	
	public long getSize() throws IOException {
		return raf.length();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy