本文整理匯總了Java中java.io.RandomAccessFile.writeLong方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomAccessFile.writeLong方法的具體用法?Java RandomAccessFile.writeLong怎麽用?Java RandomAccessFile.writeLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.RandomAccessFile
的用法示例。
在下文中一共展示了RandomAccessFile.writeLong方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doTestCorruptCheckpointMeta
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private void doTestCorruptCheckpointMeta(boolean backup) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
if (backup) {
Thread.sleep(2000);
}
channel.stop();
File checkpoint = new File(checkpointDir, "checkpoint");
RandomAccessFile writer = new RandomAccessFile(Serialization.getMetaDataFile(checkpoint), "rw");
writer.seek(10);
writer.writeLong(new Random().nextLong());
writer.getFD().sync();
writer.close();
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
Assert.assertTrue(!backup || channel.checkpointBackupRestored());
Set<String> out = consumeChannel(channel);
compareInputAndOut(in, out);
}
示例2: testCheckpointBadVersion
import java.io.RandomAccessFile; //導入方法依賴的package包/類
@Test(expected = BadCheckpointException.class)
public void testCheckpointBadVersion() throws Exception {
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
try {
EventQueueBackingStore backingStore =
EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
writer.seek(EventQueueBackingStoreFile.INDEX_VERSION * Serialization.SIZE_OF_LONG);
writer.writeLong(94L);
writer.getFD().sync();
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
} finally {
writer.close();
}
}
示例3: testIncompleteCheckpoint
import java.io.RandomAccessFile; //導入方法依賴的package包/類
@Test(expected = BadCheckpointException.class)
public void testIncompleteCheckpoint() throws Exception {
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
try {
EventQueueBackingStore backingStore =
EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
writer.seek(EventQueueBackingStoreFile.INDEX_CHECKPOINT_MARKER * Serialization.SIZE_OF_LONG);
writer.writeLong(EventQueueBackingStoreFile.CHECKPOINT_INCOMPLETE);
writer.getFD().sync();
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
} finally {
writer.close();
}
}
示例4: testCorruptMeta
import java.io.RandomAccessFile; //導入方法依賴的package包/類
@Test(expected = InvalidProtocolBufferException.class)
public void testCorruptMeta() throws Throwable {
EventQueueBackingStore backingStore =
EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
Assert.assertTrue(checkpoint.exists());
File metaFile = Serialization.getMetaDataFile(checkpoint);
Assert.assertTrue(metaFile.length() != 0);
RandomAccessFile writer = new RandomAccessFile(metaFile, "rw");
writer.seek(10);
writer.writeLong(new Random().nextLong());
writer.getFD().sync();
writer.close();
try {
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
} catch (BadCheckpointException ex) {
throw ex.getCause();
}
}
示例5: getImageFileMD5IgnoringTxId
import java.io.RandomAccessFile; //導入方法依賴的package包/類
/**
* Calculate the md5sum of an image after zeroing out the transaction ID
* field in the header. This is useful for tests that want to verify
* that two checkpoints have identical namespaces.
*/
public static String getImageFileMD5IgnoringTxId(File imageFile)
throws IOException {
File tmpFile = File.createTempFile("hadoop_imagefile_tmp", "fsimage");
tmpFile.deleteOnExit();
try {
Files.copy(imageFile, tmpFile);
RandomAccessFile raf = new RandomAccessFile(tmpFile, "rw");
try {
raf.seek(IMAGE_TXID_POS);
raf.writeLong(0);
} finally {
IOUtils.closeStream(raf);
}
return getFileMD5(tmpFile);
} finally {
tmpFile.delete();
}
}
示例6: initMarker
import java.io.RandomAccessFile; //導入方法依賴的package包/類
/**
* 初始化marker文件信息
* @param marker marker文件操作對象
* @param currentPointer 當前操作偏移量
* @throws IOException
*/
public synchronized static void initMarker(RandomAccessFile marker, long currentPointer) throws IOException{
//設置到此文件開頭測量到的文件指針偏移量,在該位置發生下一個讀取或寫入操作
marker.seek(0);
marker.writeLong(currentPointer);
//maker.writeBytes(count + "\r\n");
}
示例7: markCheckpoint
import java.io.RandomAccessFile; //導入方法依賴的package包/類
@Override
void markCheckpoint(long currentPosition, long logWriteOrderID)
throws IOException {
RandomAccessFile writeFileHandle = getFileHandle();
writeFileHandle.seek(OFFSET_CHECKPOINT);
writeFileHandle.writeLong(currentPosition);
writeFileHandle.writeLong(logWriteOrderID);
writeFileHandle.getChannel().force(true);
LOGGER.info("Noted checkpoint for file: " + getFile() + ", id: "
+ getLogFileID() + ", checkpoint position: " + currentPosition
+ ", logWriteOrderID: " + logWriteOrderID);
}
示例8: Writer
import java.io.RandomAccessFile; //導入方法依賴的package包/類
Writer(File file, int logFileID, long maxFileSize,
long usableSpaceRefreshInterval)
throws IOException {
super(file, logFileID, maxFileSize, null, usableSpaceRefreshInterval,
true, 0);
RandomAccessFile writeFileHandle = getFileHandle();
writeFileHandle.writeInt(getVersion());
writeFileHandle.writeInt(logFileID);
// checkpoint marker
writeFileHandle.writeLong(0L);
// timestamp placeholder
writeFileHandle.writeLong(0L);
getFileChannel().force(true);
}
示例9: doTestBadCheckpointVersion
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private void doTestBadCheckpointVersion(boolean backup) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
if (backup) {
Thread.sleep(2000);
}
channel.stop();
File checkpoint = new File(checkpointDir, "checkpoint");
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
writer.seek(EventQueueBackingStoreFile.INDEX_VERSION *
Serialization.SIZE_OF_LONG);
writer.writeLong(2L);
writer.getFD().sync();
writer.close();
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
Assert.assertTrue(!backup || channel.checkpointBackupRestored());
Set<String> out = consumeChannel(channel);
compareInputAndOut(in, out);
}
示例10: doTestIncompleteCheckpoint
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private void doTestIncompleteCheckpoint(boolean backup) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
if (backup) {
Thread.sleep(2000);
}
channel.stop();
File checkpoint = new File(checkpointDir, "checkpoint");
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
writer.seek(EventQueueBackingStoreFile.INDEX_CHECKPOINT_MARKER
* Serialization.SIZE_OF_LONG);
writer.writeLong(EventQueueBackingStoreFile.CHECKPOINT_INCOMPLETE);
writer.getFD().sync();
writer.close();
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
Assert.assertTrue(!backup || channel.checkpointBackupRestored());
Set<String> out = consumeChannel(channel);
compareInputAndOut(in, out);
}
示例11: testFastReplay
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private void testFastReplay(boolean shouldCorruptCheckpoint, boolean useFastReplay)
throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_FAST_REPLAY,
String.valueOf(useFastReplay));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
channel.stop();
if (shouldCorruptCheckpoint) {
File checkpoint = new File(checkpointDir, "checkpoint");
RandomAccessFile writer = new RandomAccessFile(
Serialization.getMetaDataFile(checkpoint),
"rw");
writer.seek(10);
writer.writeLong(new Random().nextLong());
writer.getFD().sync();
writer.close();
}
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
Set<String> out = consumeChannel(channel);
if (useFastReplay && shouldCorruptCheckpoint) {
Assert.assertTrue(channel.didFastReplay());
} else {
Assert.assertFalse(channel.didFastReplay());
}
compareInputAndOut(in, out);
}
示例12: testCheckpointVersionNotEqualToMeta
import java.io.RandomAccessFile; //導入方法依賴的package包/類
@Test(expected = BadCheckpointException.class)
public void testCheckpointVersionNotEqualToMeta() throws Exception {
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
try {
EventQueueBackingStore backingStore =
EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
writer.seek(EventQueueBackingStoreFile.INDEX_VERSION * Serialization.SIZE_OF_LONG);
writer.writeLong(2L);
writer.getFD().sync();
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
} finally {
writer.close();
}
}
示例13: testCheckpointOrderIdNotEqualToMeta
import java.io.RandomAccessFile; //導入方法依賴的package包/類
@Test(expected = BadCheckpointException.class)
public void testCheckpointOrderIdNotEqualToMeta() throws Exception {
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
try {
EventQueueBackingStore backingStore =
EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
writer.seek(EventQueueBackingStoreFile.INDEX_WRITE_ORDER_ID * Serialization.SIZE_OF_LONG);
writer.writeLong(2L);
writer.getFD().sync();
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
} finally {
writer.close();
}
}
示例14: q
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public static void q() {
try {
if (bZ != null) {
b7 = new File(bZ);
if (!b7.exists()) {
File file = new File(I);
if (!file.exists()) {
file.mkdirs();
}
b7.createNewFile();
RandomAccessFile randomAccessFile = new RandomAccessFile(b7, "rw");
randomAccessFile.seek(0);
randomAccessFile.writeInt(-1);
randomAccessFile.writeInt(-1);
randomAccessFile.writeInt(0);
randomAccessFile.writeLong(0);
randomAccessFile.writeInt(0);
randomAccessFile.writeInt(0);
randomAccessFile.close();
return;
}
return;
}
b7 = null;
} catch (Exception e) {
b7 = null;
}
}
示例15: testValidateEditLogWithCorruptHeader
import java.io.RandomAccessFile; //導入方法依賴的package包/類
@Test
public void testValidateEditLogWithCorruptHeader() throws IOException {
File testDir = new File(TEST_DIR, "testValidateEditLogWithCorruptHeader");
SortedMap<Long, Long> offsetToTxId = Maps.newTreeMap();
File logFile = prepareUnfinalizedTestEditLog(testDir, 2, offsetToTxId);
RandomAccessFile rwf = new RandomAccessFile(logFile, "rw");
try {
rwf.seek(0);
rwf.writeLong(42); // corrupt header
} finally {
rwf.close();
}
EditLogValidation validation = EditLogFileInputStream.validateEditLog(logFile);
assertTrue(validation.hasCorruptHeader());
}