当前位置: 首页>>代码示例>>Java>>正文


Java RandomAccessFile.readByte方法代码示例

本文整理汇总了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;
}
 
开发者ID:aro,项目名称:app-logbrowser,代码行数:27,代码来源:LogFileHandler.java

示例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);
}
 
开发者ID:BITPlan,项目名称:can4eve,代码行数:30,代码来源:RandomAccessLogReader.java

示例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();
}
 
开发者ID:Achenglove,项目名称:AndroidVideoCache,代码行数:15,代码来源:Files.java

示例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;
    }
}
 
开发者ID:aro,项目名称:app-logbrowser,代码行数:13,代码来源:LogFileHandler.java

示例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;
}
 
开发者ID:xiongbeer,项目名称:Cobweb,代码行数:17,代码来源:DirectDiskUrlFilter.java

示例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);
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:33,代码来源:LogFile.java

示例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;
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:47,代码来源:OggPageHeader.java

示例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;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:42,代码来源:OggPageHeader.java

示例9: getCharValue

import java.io.RandomAccessFile; //导入方法依赖的package包/类
protected char getCharValue(RandomAccessFile file, int pointer) throws IOException {
    file.seek(pointer);
    return (char) file.readByte();
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:5,代码来源:OpticalImageReader.java


注:本文中的java.io.RandomAccessFile.readByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。