本文整理汇总了Java中java.io.RandomAccessFile.readByte方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.readByte方法的具体用法?Java RandomAccessFile.readByte怎么用?Java RandomAccessFile.readByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.RandomAccessFile
的用法示例。
在下文中一共展示了RandomAccessFile.readByte方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findNextLineStart
import java.io.RandomAccessFile; //导入方法依赖的package包/类
private long findNextLineStart( final RandomAccessFile file, final Long from )
throws IOException
{
final long fileLength = file.length() - 1;
long filePointer;
for ( filePointer = from; filePointer < fileLength && filePointer != -1; filePointer++ )
{
file.seek( filePointer );
int readByte = file.readByte();
if ( readByte == LF )
{
filePointer++;
break;
}
if ( readByte == CR )
{
if ( readByte( file, filePointer + 1 ) == LF )
{
filePointer++;
}
filePointer++;
break;
}
}
return filePointer;
}
示例2: getPacket
import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* get a line from the Random Access file
*
* @param raf
* - the random access file
* @param start
* @return
* @throws Exception
*/
public PacketSeek getPacket(RandomAccessFile raf, long start)
throws Exception {
// we want an even start if 2 bytes per char
// long pos = (start % 2 == 0) ? start : start - 1;
long pos = start;
if (pos == 0) {
return nextPacket(raf);
}
byte b;
int count = 0;
// seek backward
do {
pos -= 1;
raf.seek(pos);
checkCountLimit("char", count++, true);
} while (pos > 0 && raf.readByte() != 0x0a);
// pos = (pos <= 0) ? 0 : pos + 2;
// raf.seek(pos);
return nextPacket(raf);
}
示例3: modify
import java.io.RandomAccessFile; //导入方法依赖的package包/类
static void modify(File file) throws IOException {
long size = file.length();
if (size == 0) {
recreateZeroSizeFile(file);
return;
}
RandomAccessFile accessFile = new RandomAccessFile(file, "rwd");
accessFile.seek(size - 1);
byte lastByte = accessFile.readByte();
accessFile.seek(size - 1);
accessFile.write(lastByte);
accessFile.close();
}
示例4: readByte
import java.io.RandomAccessFile; //导入方法依赖的package包/类
private int readByte( final RandomAccessFile file, final long position )
{
try
{
file.seek( position );
return file.readByte();
}
catch ( IOException e )
{
return -1;
}
}
示例5: DirectDiskUrlFilter
import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* @param filterPath 原Guava序列化存储的文件路径
* @param funnel 原Guava BloomFilter使用的Funnel
* @throws IOException
*/
public DirectDiskUrlFilter(String filterPath, Funnel<CharSequence> funnel) throws IOException {
filterFile = new File(filterPath);
raf = new RandomAccessFile(filterFile, "rw");
/* jump strategyOrdinal value */
raf.readByte();
numHashFunctions = UnsignedBytes.toInt(raf.readByte());
dataLength = raf.readInt();
bitsSize = (long) dataLength * 64L;
bits = new Bits();
this.funnel = funnel;
}
示例6: get
import java.io.RandomAccessFile; //导入方法依赖的package包/类
FlumeEvent get(int offset) throws IOException, InterruptedException,
CorruptEventException, NoopRecordException {
Preconditions.checkState(open, "File closed");
RandomAccessFile fileHandle = checkOut();
boolean error = true;
try {
fileHandle.seek(offset);
byte operation = fileHandle.readByte();
if (operation == OP_NOOP) {
throw new NoopRecordException("No op record found. Corrupt record " +
"may have been repaired by File Channel Integrity tool");
}
if (operation != OP_RECORD) {
throw new CorruptEventException(
"Operation code is invalid. File " +
"is corrupt. Please run File Channel Integrity tool.");
}
TransactionEventRecord record = doGet(fileHandle);
if (!(record instanceof Put)) {
Preconditions.checkState(false, "Record is " +
record.getClass().getSimpleName());
}
error = false;
return ((Put) record).getEvent();
} finally {
if (error) {
close(fileHandle, file);
} else {
checkIn(fileHandle);
}
}
}
示例7: read
import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Read next PageHeader from file
* @param raf
* @return
* @throws IOException
* @throws CannotReadException
*/
public static OggPageHeader read(RandomAccessFile raf) throws IOException, CannotReadException
{
long start = raf.getFilePointer();
logger.fine("Trying to read OggPage at:" + start);
byte[] b = new byte[OggPageHeader.CAPTURE_PATTERN.length];
raf.read(b);
if (!(Arrays.equals(b, OggPageHeader.CAPTURE_PATTERN)))
{
raf.seek(start);
if(AbstractID3v2Tag.isId3Tag(raf))
{
logger.warning(ErrorMessage.OGG_CONTAINS_ID3TAG.getMsg(raf.getFilePointer() - start));
raf.read(b);
if ((Arrays.equals(b, OggPageHeader.CAPTURE_PATTERN)))
{
//Go to the end of the ID3 header
start=raf.getFilePointer() - OggPageHeader.CAPTURE_PATTERN.length;
}
}
else
{
throw new CannotReadException(ErrorMessage.OGG_HEADER_CANNOT_BE_FOUND.getMsg(new String(b)));
}
}
raf.seek(start + OggPageHeader.FIELD_PAGE_SEGMENTS_POS);
int pageSegments = raf.readByte() & 0xFF; //unsigned
raf.seek(start);
b = new byte[OggPageHeader.OGG_PAGE_HEADER_FIXED_LENGTH + pageSegments];
raf.read(b);
OggPageHeader pageHeader = new OggPageHeader(b);
pageHeader.setStartByte(start);
//Now just after PageHeader, ready for Packet Data
return pageHeader;
}
示例8: read
import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Read next PageHeader from file
*
* @param raf
* @return
* @throws IOException
* @throws CannotReadException
*/
public static OggPageHeader read(RandomAccessFile raf) throws IOException, CannotReadException {
long start = raf.getFilePointer();
logger.fine("Trying to read OggPage at:" + start);
byte[] b = new byte[OggPageHeader.CAPTURE_PATTERN.length];
raf.read(b);
if (!(Arrays.equals(b, OggPageHeader.CAPTURE_PATTERN))) {
raf.seek(start);
if (AbstractID3v2Tag.isId3Tag(raf)) {
logger.warning(ErrorMessage.OGG_CONTAINS_ID3TAG.getMsg(raf.getFilePointer() - start));
raf.read(b);
if ((Arrays.equals(b, OggPageHeader.CAPTURE_PATTERN))) {
//Go to the end of the ID3 header
start = raf.getFilePointer() - OggPageHeader.CAPTURE_PATTERN.length;
}
} else {
throw new CannotReadException(ErrorMessage.OGG_HEADER_CANNOT_BE_FOUND.getMsg(new String(b)));
}
}
raf.seek(start + OggPageHeader.FIELD_PAGE_SEGMENTS_POS);
int pageSegments = raf.readByte() & 0xFF; //unsigned
raf.seek(start);
b = new byte[OggPageHeader.OGG_PAGE_HEADER_FIXED_LENGTH + pageSegments];
raf.read(b);
OggPageHeader pageHeader = new OggPageHeader(b);
pageHeader.setStartByte(start);
//Now just after PageHeader, ready for Packet Data
return pageHeader;
}
示例9: getCharValue
import java.io.RandomAccessFile; //导入方法依赖的package包/类
protected char getCharValue(RandomAccessFile file, int pointer) throws IOException {
file.seek(pointer);
return (char) file.readByte();
}