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


Java RandomAccessFile.writeLong方法代码示例

本文整理汇总了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);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:27,代码来源:TestFileChannelRestart.java

示例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();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:17,代码来源:TestEventQueueBackingStoreFactory.java

示例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();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:17,代码来源:TestEventQueueBackingStoreFactory.java

示例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();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:TestEventQueueBackingStoreFactory.java

示例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();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:FSImageTestUtil.java

示例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");
}
 
开发者ID:andy-huaan,项目名称:data-queue,代码行数:13,代码来源:FileUtils.java

示例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);

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:14,代码来源:LogFileV2.java

示例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);

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:16,代码来源:LogFileV2.java

示例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);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:28,代码来源:TestFileChannelRestart.java

示例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);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:28,代码来源:TestFileChannelRestart.java

示例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);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:34,代码来源:TestFileChannelRestart.java

示例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();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:16,代码来源:TestEventQueueBackingStoreFactory.java

示例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();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:16,代码来源:TestEventQueueBackingStoreFactory.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:29,代码来源:l.java

示例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());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:TestFSEditLogLoader.java


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