本文整理汇总了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");
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
示例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();
}
}
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}