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


Java RandomAccessFile.readInt方法代码示例

本文整理汇总了Java中java.io.RandomAccessFile.readInt方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.readInt方法的具体用法?Java RandomAccessFile.readInt怎么用?Java RandomAccessFile.readInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.RandomAccessFile的用法示例。


在下文中一共展示了RandomAccessFile.readInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findCentralDirectory

import java.io.RandomAccessFile; //导入方法依赖的package包/类
static CentralDirectory findCentralDirectory(RandomAccessFile raf) throws IOException, ZipException {
    long scanOffset = raf.length() - 22;
    if (scanOffset < 0) {
        throw new ZipException("File too short to be a zip file: " + raf.length());
    }
    long stopOffset = scanOffset - 65536;
    if (stopOffset < 0) {
        stopOffset = 0;
    }
    int endSig = Integer.reverseBytes(ENDSIG);
    do {
        raf.seek(scanOffset);
        if (raf.readInt() == endSig) {
            raf.skipBytes(2);
            raf.skipBytes(2);
            raf.skipBytes(2);
            raf.skipBytes(2);
            CentralDirectory dir = new CentralDirectory();
            dir.size = ((long) Integer.reverseBytes(raf.readInt())) & 4294967295L;
            dir.offset = ((long) Integer.reverseBytes(raf.readInt())) & 4294967295L;
            return dir;
        }
        scanOffset--;
    } while (scanOffset >= stopOffset);
    throw new ZipException("End Of Central Directory signature not found");
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:27,代码来源:ZipUtil.java

示例2: readDelimitedBuffer

import java.io.RandomAccessFile; //导入方法依赖的package包/类
protected static byte[] readDelimitedBuffer(RandomAccessFile fileHandle)
    throws IOException, CorruptEventException {
  int length = fileHandle.readInt();
  if (length < 0) {
    throw new CorruptEventException("Length of event is: " + String.valueOf(length) +
        ". Event must have length >= 0. Possible corruption of data or partial fsync.");
  }
  byte[] buffer = new byte[length];
  try {
    fileHandle.readFully(buffer);
  } catch (EOFException ex) {
    throw new CorruptEventException("Remaining data in file less than " +
                                    "expected size of event.", ex);
  }
  return buffer;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:17,代码来源:LogFile.java

示例3: restoreFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/** todo - take account of incomplete addition of block due to lack of disk */

    // buggy database files had size == position == 0 at the end
    public static void restoreFile(String sourceName,
                                   String destName) throws IOException {

        RandomAccessFile source = new RandomAccessFile(sourceName, "r");
        RandomAccessFile dest   = new RandomAccessFile(destName, "rw");

        while (source.getFilePointer() != source.length()) {
            int    size     = source.readInt();
            long   position = source.readLong();
            byte[] buffer   = new byte[size];

            source.read(buffer);
            dest.seek(position);
            dest.write(buffer);
        }
        source.close();
        dest.close();
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:RAShadowFile.java

示例4: restoreFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/** todo - take account of incomplete addition of block due to lack of disk */

    // buggy database files had size == position == 0 at the end
    public static void restoreFile(String sourceName,
                                   String destName) throws IOException {

        RandomAccessFile source = new RandomAccessFile(sourceName, "r");
        RandomAccessFile dest   = new RandomAccessFile(destName, "rw");

        while (source.getFilePointer() != source.length()) {
            int    size     = source.readInt();
            long   position = source.readLong();
            byte[] buffer   = new byte[size];

            source.read(buffer, 0, buffer.length);
            dest.seek(position);
            dest.write(buffer, 0, buffer.length);
        }

        source.close();
        dest.close();
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:23,代码来源:RAShadowFile.java

示例5: isPreUpgradableLayout

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@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.cleanup(LOG, oldFile);
  }
  return true;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:NNStorage.java

示例6: isPreUpgradableLayout

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@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
  RandomAccessFile oldFile = new RandomAccessFile(oldF, "rws");
  FileLock oldLock = oldFile.getChannel().tryLock();
  try {
    oldFile.seek(0);
    int oldVersion = oldFile.readInt();
    if (oldVersion < LAST_PRE_UPGRADE_LAYOUT_VERSION)
      return false;
  } finally {
    oldLock.release();
    oldFile.close();
  }
  return true;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:DataStorage.java

示例7: findCentralDirectory

import java.io.RandomAccessFile; //导入方法依赖的package包/类
static CentralDirectory findCentralDirectory(RandomAccessFile raf) throws IOException,
        ZipException {
    long scanOffset = raf.length() - ENDHDR;
    if (scanOffset < 0) {
        throw new ZipException("File too short to be a zip file: " + raf.length());
    }

    long stopOffset = scanOffset - 0x10000 /* ".ZIP file comment"'s max length */;
    if (stopOffset < 0) {
        stopOffset = 0;
    }

    int endSig = Integer.reverseBytes(ENDSIG);
    while (true) {
        raf.seek(scanOffset);
        if (raf.readInt() == endSig) {
            break;
        }

        scanOffset--;
        if (scanOffset < stopOffset) {
            throw new ZipException("End Of Central Directory signature not found");
        }
    }
    // Read the End Of Central Directory. ENDHDR includes the signature
    // bytes,
    // which we've already read.

    // Pull out the information we need.
    raf.skipBytes(2); // diskNumber
    raf.skipBytes(2); // diskWithCentralDir
    raf.skipBytes(2); // numEntries
    raf.skipBytes(2); // totalNumEntries
    CentralDirectory dir = new CentralDirectory();
    dir.size = Integer.reverseBytes(raf.readInt()) & 0xFFFFFFFFL;
    dir.offset = Integer.reverseBytes(raf.readInt()) & 0xFFFFFFFFL;
    return dir;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:39,代码来源:ZipUtil.java

示例8: isElf

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public static boolean isElf(File f) {
	long n = 0;
	try {
		RandomAccessFile raf = new RandomAccessFile(f, "r");
		n = raf.readInt();
		raf.close();
	} catch (IOException ex) {
		System.out.println(ex);
	}
	return n == 0x7F454C46;
}
 
开发者ID:seaase,项目名称:Elf-Editor,代码行数:12,代码来源:Elf.java

示例9: 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

示例10: getRandomReader

import java.io.RandomAccessFile; //导入方法依赖的package包/类
static LogFile.RandomReader getRandomReader(File file,
                                            @Nullable KeyProvider encryptionKeyProvider,
                                            boolean fsyncPerTransaction)
    throws IOException {
  RandomAccessFile logFile = new RandomAccessFile(file, "r");
  try {
    File metaDataFile = Serialization.getMetaDataFile(file);
    // either this is a rr for a just created file or
    // the metadata file exists and as such it's V3
    if (logFile.length() == 0L || metaDataFile.exists()) {
      return new LogFileV3.RandomReader(file, encryptionKeyProvider,
          fsyncPerTransaction);
    }
    int version = logFile.readInt();
    if (Serialization.VERSION_2 == version) {
      return new LogFileV2.RandomReader(file);
    }
    throw new IOException("File " + file + " has bad version " +
        Integer.toHexString(version));
  } finally {
    if (logFile != null) {
      try {
        logFile.close();
      } catch (IOException e) {
        LOGGER.warn("Unable to close " + file, e);
      }
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:30,代码来源:LogFileFactory.java

示例11: MetaDataWriter

import java.io.RandomAccessFile; //导入方法依赖的package包/类
protected MetaDataWriter(File file, int logFileID) throws IOException {
  super(file, logFileID);
  boolean error = true;
  try {
    RandomAccessFile writeFileHandle = getFileHandle();
    int version = writeFileHandle.readInt();
    if (version != getVersion()) {
      throw new IOException("The version of log file: "
          + file.getCanonicalPath() + " is different from expected "
          + " version: expected = " + getVersion() + ", found = " + version);
    }
    int fid = writeFileHandle.readInt();
    if (fid != logFileID) {
      throw new IOException("The file id of log file: "
          + file.getCanonicalPath() + " is different from expected "
          + " id: expected = " + logFileID + ", found = " + fid);
    }
    setLastCheckpointOffset(writeFileHandle.readLong());
    setLastCheckpointWriteOrderID(writeFileHandle.readLong());
    LOGGER.info("File: " + file.getCanonicalPath() + " was last checkpointed "
        + "at position: " + getLastCheckpointOffset()
        + ", logWriteOrderID: " + getLastCheckpointWriteOrderID());
    error = false;
  } finally {
    if (error) {
      close();
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:30,代码来源:LogFileV2.java

示例12: SequentialReader

import java.io.RandomAccessFile; //导入方法依赖的package包/类
SequentialReader(File file) throws EOFException, IOException {
  super(file, null);
  RandomAccessFile fileHandle = getFileHandle();
  int version = fileHandle.readInt();
  if (version != getVersion()) {
    throw new IOException("Version is " + Integer.toHexString(version) +
        " expected " + Integer.toHexString(getVersion())
        + " file: " + file.getCanonicalPath());
  }
  setLogFileID(fileHandle.readInt());
  setLastCheckpointPosition(fileHandle.readLong());
  setLastCheckpointWriteOrderID(fileHandle.readLong());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:14,代码来源:LogFileV2.java

示例13: loadSummary

import java.io.RandomAccessFile; //导入方法依赖的package包/类
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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:30,代码来源:FSImageUtil.java

示例14: skipRecord

import java.io.RandomAccessFile; //导入方法依赖的package包/类
protected static void skipRecord(RandomAccessFile fileHandle,
                                 int offset) throws IOException {
  fileHandle.seek(offset);
  int length = fileHandle.readInt();
  fileHandle.skipBytes(length);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:7,代码来源:LogFile.java

示例15: onBackup

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
        ParcelFileDescriptor newState) throws IOException {
    // First, get the current data from the application's file.  This
    // may throw an IOException, but in that case something has gone
    // badly wrong with the app's data on disk, and we do not want
    // to back up garbage data.  If we just let the exception go, the
    // Backup Manager will handle it and simply skip the current
    // backup operation.
    synchronized (BackupRestoreActivity.sDataLock) {
        RandomAccessFile file = new RandomAccessFile(mDataFile, "r");
        mFilling = file.readInt();
        mAddMayo = file.readBoolean();
        mAddTomato = file.readBoolean();
    }

    // If this is the first backup ever, we have to back up everything
    boolean forceBackup = (oldState == null);

    // Now read the state as of the previous backup pass, if any
    int lastFilling = 0;
    boolean lastMayo = false;
    boolean lastTomato = false;

    if (!forceBackup) {

        FileInputStream instream = new FileInputStream(oldState.getFileDescriptor());
        DataInputStream in = new DataInputStream(instream);

        try {
            // Read the state as of the last backup
            lastFilling = in.readInt();
            lastMayo = in.readBoolean();
            lastTomato = in.readBoolean();
        } catch (IOException e) {
            // If something went wrong reading the state file, be safe and
            // force a backup of all the data again.
            forceBackup = true;
        }
    }

    // Okay, now check each datum to see whether we need to back up a new value.  We'll
    // reuse the bytearray buffering stream for each datum.  We also use a little
    // helper routine to avoid some code duplication when writing the two boolean
    // records.
    ByteArrayOutputStream bufStream = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(bufStream);

    if (forceBackup || (mFilling != lastFilling)) {
        // bufStream.reset();   // not necessary the first time, but good to remember
        out.writeInt(mFilling);
        writeBackupEntity(data, bufStream, FILLING_KEY);
    }

    if (forceBackup || (mAddMayo != lastMayo)) {
        bufStream.reset();
        out.writeBoolean(mAddMayo);
        writeBackupEntity(data, bufStream, MAYO_KEY);
    }

    if (forceBackup || (mAddTomato != lastTomato)) {
        bufStream.reset();
        out.writeBoolean(mAddTomato);
        writeBackupEntity(data, bufStream, TOMATO_KEY);
    }

    // Finally, write the state file that describes our data as of this backup pass
    writeStateFile(newState);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:70,代码来源:MultiRecordExampleAgent.java


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