本文整理汇总了Java中java.io.RandomAccessFile.writeByte方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.writeByte方法的具体用法?Java RandomAccessFile.writeByte怎么用?Java RandomAccessFile.writeByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.RandomAccessFile
的用法示例。
在下文中一共展示了RandomAccessFile.writeByte方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEqual
import java.io.RandomAccessFile; //导入方法依赖的package包/类
public void testEqual() throws IOException {
File asciiFile = getTestFile("ascii.txt");
File i18nFile = getTestFile("i18n.txt");
assertFalse(Files.equal(asciiFile, i18nFile));
assertTrue(Files.equal(asciiFile, asciiFile));
File temp = createTempFile();
Files.copy(asciiFile, temp);
assertTrue(Files.equal(asciiFile, temp));
Files.copy(i18nFile, temp);
assertTrue(Files.equal(i18nFile, temp));
Files.copy(asciiFile, temp);
RandomAccessFile rf = new RandomAccessFile(temp, "rw");
rf.writeByte(0);
rf.close();
assertEquals(asciiFile.length(), temp.length());
assertFalse(Files.equal(asciiFile, temp));
assertTrue(Files.asByteSource(asciiFile)
.contentEquals(Files.asByteSource(asciiFile)));
// 0-length files have special treatment (/proc, etc.)
assertTrue(Files.equal(asciiFile, new BadLengthFile(asciiFile, 0)));
}
示例2: storeToFile
import java.io.RandomAccessFile; //导入方法依赖的package包/类
public int storeToFile(RandomAccessFile file) {
int totalSize = 0;
if (null != file) {
try {
file.writeInt(mCodes.size());
Iterator<ExprCode> iterator = mCodes.keySet().iterator();
while (iterator.hasNext()) {
ExprCode code = iterator.next();
Integer integer = mCodes.get(code);
file.writeInt(integer.intValue());
file.writeShort(code.size());
for (byte b : code.mCodeBase) {
file.writeByte(b);
}
totalSize += 4 + code.size() + 2;
}
} catch (IOException e) {
Log.e(TAG, "storeToFile error:" + e);
e.printStackTrace();
}
}
return totalSize;
}
示例3: corruptByteInFile
import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Corrupt the byte at the given offset in the given file,
* by subtracting 1 from it.
*/
private void corruptByteInFile(File file, long offset)
throws IOException {
RandomAccessFile raf = new RandomAccessFile(file, "rw");
try {
raf.seek(offset);
int origByte = raf.read();
raf.seek(offset);
raf.writeByte(origByte - 1);
} finally {
IOUtils.closeStream(raf);
}
}
示例4: testChannelDiesOnCorruptEvent
import java.io.RandomAccessFile; //导入方法依赖的package包/类
private void testChannelDiesOnCorruptEvent(boolean fsyncPerTxn) throws Exception {
Map<String, String> overrides = new HashMap<String, String>();
overrides.put(FileChannelConfiguration.FSYNC_PER_TXN, String.valueOf(fsyncPerTxn));
final FileChannel channel = createFileChannel(overrides);
channel.start();
putEvents(channel,"test-corrupt-event",100,100);
for (File dataDir : dataDirs) {
File[] files = dataDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (!name.endsWith("meta") && !name.contains("lock")) {
return true;
}
return false;
}
});
if (files != null && files.length > 0) {
for (int j = 0; j < files.length; j++) {
RandomAccessFile fileToCorrupt = new RandomAccessFile(files[0], "rw");
fileToCorrupt.seek(50);
fileToCorrupt.writeByte(234);
fileToCorrupt.close();
}
}
}
Set<String> events;
try {
events = consumeChannel(channel, true);
} catch (IllegalStateException ex) {
// The rollback call in takeEvents() in TestUtils will cause an
// IllegalArgumentException - and this should be tested to verify the
// channel is completely stopped.
Assert.assertTrue(ex.getMessage().contains("Log is closed"));
throw ex;
}
if (fsyncPerTxn) {
Assert.fail();
} else {
// The corrupt event must be missing, the rest should be
// returned
Assert.assertEquals(99, events.size());
}
}