java.io.RandomAccessFile.readInt()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中java.io.RandomAccessFile.readInt方法的一些代码示例,展示了RandomAccessFile.readInt的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RandomAccessFile.readInt方法的具体详情如下:
包路径:java.io.RandomAccessFile
类名称:RandomAccessFile
方法名:readInt

RandomAccessFile.readInt介绍

[英]Reads a big-endian 32-bit integer from the current position in this file. Blocks until four bytes have been read, the end of the file is reached or an exception is thrown.
[中]从文件中的当前位置读取一个大端32位整数。块,直到读取了四个字节,到达文件末尾或引发异常。

代码示例

代码示例来源:origin: apache/flume

protected static void skipRecord(RandomAccessFile fileHandle,
                 int offset) throws IOException {
 fileHandle.seek(offset);
 int length = fileHandle.readInt();
 fileHandle.skipBytes(length);
}

代码示例来源:origin: graphhopper/graphhopper

protected long readHeader(RandomAccessFile raFile) throws IOException {
  raFile.seek(0);
  if (raFile.length() == 0)
    return -1;
  String versionHint = raFile.readUTF();
  if (!"GH".equals(versionHint))
    throw new IllegalArgumentException("Not a GraphHopper file! Expected 'GH' as file marker but was " + versionHint);
  long bytes = raFile.readLong();
  setSegmentSize(raFile.readInt());
  for (int i = 0; i < header.length; i++) {
    header[i] = raFile.readInt();
  }
  return bytes;
}

代码示例来源:origin: jenkinsci/jenkins

psinfo.seek(8);
if(adjust(psinfo.readInt())!=pid)
  throw new IOException("psinfo PID mismatch");   // sanity check
ppid = adjust(psinfo.readInt());
  psinfo.seek(236);  // offset of pr_argc
  argc = adjust(psinfo.readInt());
  argp = adjustL(psinfo.readLong());
  envp = adjustL(psinfo.readLong());
  b64 = (psinfo.readByte() == PR_MODEL_LP64);
} else {
  psinfo.seek(188);  // offset of pr_argc
  argc = adjust(psinfo.readInt());
  argp = to64(adjust(psinfo.readInt()));
  envp = to64(adjust(psinfo.readInt()));
  b64 = (psinfo.readByte() == PR_MODEL_LP64);

代码示例来源:origin: lealone/Lealone

private synchronized TreeSet<Long> readRemovedPages() {
  try {
    TreeSet<Long> removedPages = new TreeSet<>();
    if (chunkMetaData.length() > 8) {
      chunkMetaData.seek(4);
      int removedPagesCount = chunkMetaData.readInt();
      for (int i = 0; i < removedPagesCount; i++)
        removedPages.add(chunkMetaData.readLong());
    }
    return removedPages;
  } catch (IOException e) {
    throw panic(DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, "Failed to readRemovedPages",
        e));
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

file.seek(sectorNumber * SECTOR_BYTES);
int length = file.readInt();
if (length > SECTOR_BYTES * numSectors) {
  throw new IOException("Invalid length: " + length + " > " + SECTOR_BYTES * numSectors);
    if (e.getMessage().equals("Not in GZIP format")) {
      GlowServer.logger.info("Incorrect region version, switching to zlib...");
      file.seek((sectorNumber * SECTOR_BYTES) + Integer.BYTES);
      file.write(VERSION_DEFLATE);
      return getZlibInputStream(data);

代码示例来源:origin: osmdroid/osmdroid

baseFile.seek(offset);
dataOffset = baseFile.readLong();
dataLength = baseFile.readInt();
pDataFile.seek(dataOffset);

代码示例来源:origin: jenkinsci/jenkins

pstatus.seek(17); // offset of pr_dmodel
pstatus.seek(88); // offset of pr_pid
psinfo.seek(48); // offset of pr_pid
psinfo.seek(148); // offset of pr_argc
argc = adjust(psinfo.readInt());
pr_argp = adjustL(psinfo.readLong());
pr_envp = adjustL(psinfo.readLong());

代码示例来源:origin: Tencent/tinker

raf.seek(0);
final int headerMagic = Integer.reverseBytes(raf.readInt());
if (headerMagic != LOCSIG) {
  throw new ZipException("Not a zip archive");
  raf.seek(scanOffset);
  if (Integer.reverseBytes(raf.readInt()) == ENDSIG) {
    break;

代码示例来源:origin: voldemort/voldemort

while(true) {
  index.readFully(keyMd5);
  position = index.readInt();
  data.seek(position);
  int size = data.readInt();
  byte[] value = new byte[size];
  data.readFully(value);

代码示例来源:origin: robovm/robovm

raf.seek(0);
final int headerMagic = Integer.reverseBytes(raf.readInt());
if (headerMagic != LOCSIG) {
  throw new ZipException("Not a zip archive");
  raf.seek(scanOffset);
  if (Integer.reverseBytes(raf.readInt()) == ENDSIG) {
    break;

代码示例来源:origin: stanfordnlp/CoreNLP

hF.seek(0);
int current1 = 0;
while (current1 < current) {
 feats.xIndexed[current1] = hF.readInt();
 current1++;

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

@Override
public boolean isPreUpgradableLayout(StorageDirectory sd) throws IOException {
 File oldF = new File(sd.getRoot(), "storage");
 if (!oldF.exists()) {
  return false;
 }
 // check the layout version inside the storage file
 // Lock and Read old storage file
 try (RandomAccessFile oldFile = new RandomAccessFile(oldF, "rws");
  FileLock oldLock = oldFile.getChannel().tryLock()) {
  if (null == oldLock) {
   LOG.error("Unable to acquire file lock on path {}", oldF);
   throw new OverlappingFileLockException();
  }
  oldFile.seek(0);
  int oldVersion = oldFile.readInt();
  if (oldVersion < LAST_PRE_UPGRADE_LAYOUT_VERSION) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

@Override // Storage
public boolean isPreUpgradableLayout(StorageDirectory sd) throws IOException {
 if (disablePreUpgradableLayoutCheck) {
  return false;
 }
 File oldImageDir = new File(sd.getRoot(), "image");
 if (!oldImageDir.exists()) {
  return false;
 }
 // check the layout version inside the image file
 File oldF = new File(oldImageDir, "fsimage");
 RandomAccessFile oldFile = new RandomAccessFile(oldF, "rws");
 try {
  oldFile.seek(0);
  int oldVersion = oldFile.readInt();
  oldFile.close();
  oldFile = null;
  if (oldVersion < LAST_PRE_UPGRADE_LAYOUT_VERSION) {
   return false;
  }
 } finally {
  IOUtils.cleanupWithLogger(LOG, oldFile);
 }
 return true;
}

代码示例来源:origin: typ0520/fastdex

raf.seek(scanOffset);
  if (raf.readInt() == endSig) {
    break;
raf.skipBytes(2); // totalNumEntries
CentralDirectory dir = new CentralDirectory();
dir.size = Integer.reverseBytes(raf.readInt()) & 0xFFFFFFFFL;
dir.offset = Integer.reverseBytes(raf.readInt()) & 0xFFFFFFFFL;
return dir;

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

public static FileSummary loadSummary(RandomAccessFile file)
  throws IOException {
 final int FILE_LENGTH_FIELD_SIZE = 4;
 long fileLength = file.length();
 file.seek(fileLength - FILE_LENGTH_FIELD_SIZE);
 int summaryLength = file.readInt();
 if (summaryLength <= 0) {
  throw new IOException("Negative length of the file");
 }
 file.seek(fileLength - FILE_LENGTH_FIELD_SIZE - summaryLength);
 byte[] summaryBytes = new byte[summaryLength];
 file.readFully(summaryBytes);
 FileSummary summary = FileSummary
   .parseDelimitedFrom(new ByteArrayInputStream(summaryBytes));
 if (summary.getOndiskVersion() != FILE_VERSION) {
  throw new IOException("Unsupported file version "
    + summary.getOndiskVersion());
 }
 if (!NameNodeLayoutVersion.supports(Feature.PROTOBUF_FORMAT,
   summary.getLayoutVersion())) {
  throw new IOException("Unsupported layout version "
    + summary.getLayoutVersion());
 }
 return summary;
}

代码示例来源:origin: de.huxhorn.sulky/de.huxhorn.sulky.buffers

private long internalReadElementSize(RandomAccessFile randomSerializeFile, long offset)
  throws IOException
{
  randomSerializeFile.seek(offset);
  return randomSerializeFile.readInt();
}

代码示例来源:origin: org.ogema.ref-impl/persistence

public int getLastOffset() {
  int mapOffset = ((entryCount - 1) << 3) + 4;
  int dataOffset = -1;
  try {
    raf.seek(mapOffset);
    dataOffset = raf.readInt();
  } catch (IOException e) {
  }
  return dataOffset;
}

代码示例来源:origin: IanDarwin/javasrc

/** Read the Offset field, defined to be at location 0 in the file. */
public int readOffset() throws IOException {
  seeker.seek(0);				// move to very beginning
  return seeker.readInt();	// and read the offset
}

代码示例来源:origin: elki-project/elki

/**
 * Initializes this header from the specified file. Looks for the right
 * version and reads the integer value of {@link #pageSize} from the file.
 * 
 */
@Override
public void readHeader(RandomAccessFile file) throws IOException {
 file.seek(0);
 if(file.readInt() != FILE_VERSION) {
  throw new RuntimeException("File " + file + " is not a PersistentPageFile or wrong version!");
 }
 this.pageSize = file.readInt();
}

代码示例来源:origin: huxi/sulky

private long internalReadElementSize(RandomAccessFile randomSerializeFile, long offset)
  throws IOException
{
  randomSerializeFile.seek(offset);
  return randomSerializeFile.readInt();
}

相关文章