本文整理匯總了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());
}
}