java.io.RandomAccessFile.writeLong()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中java.io.RandomAccessFile.writeLong方法的一些代码示例,展示了RandomAccessFile.writeLong的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RandomAccessFile.writeLong方法的具体详情如下:
包路径:java.io.RandomAccessFile
类名称:RandomAccessFile
方法名:writeLong

RandomAccessFile.writeLong介绍

[英]Writes a big-endian 64-bit long to this file, starting at the current file pointer.
[中]从当前文件指针开始,向该文件写入一个64位长的大端字节。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Writes a big-endian 64-bit double to this file, starting at the current file
 * pointer. The bytes are those returned by
 * {@link Double#doubleToLongBits(double)}, meaning a canonical NaN is used.
 *
 * @param val
 *            the double to write to this file.
 * @throws IOException
 *             if an I/O error occurs while writing to this file.
 * @see #readDouble()
 */
public final void writeDouble(double val) throws IOException {
  writeLong(Double.doubleToLongBits(val));
}

代码示例来源:origin: scouter-project/scouter

public long set(long cnt) {
  this.counts = cnt;
  try {
    raf.seek(0);
    raf.writeLong(counts);
  } catch (Exception e) {
    e.printStackTrace();
  }
  return this.counts;
}

代码示例来源:origin: graphhopper/graphhopper

/**
 * Writes some internal data into the beginning of the specified file.
 */
protected void writeHeader(RandomAccessFile file, long length, int segmentSize) throws IOException {
  file.seek(0);
  file.writeUTF("GH");
  file.writeLong(length);
  file.writeInt(segmentSize);
  for (int i = 0; i < header.length; i++) {
    file.writeInt(header[i]);
  }
}

代码示例来源:origin: marytts/marytts

nBytes += 4;
for (int i = 0; i < numIdx; i++) {
  rafIn.writeLong(bytePtrs[i]);
  nBytes += 8;
  rafIn.writeLong(timePtrs[i]);
  nBytes += 8;
rafIn.writeLong(0l);
rafIn.writeLong(0l);
nBytes += 16l;

代码示例来源:origin: marytts/marytts

nBytes += 4;
for (int i = 0; i < numIdx; i++) {
  rafIn.writeLong(bytePtrs[i]);
  nBytes += 8;
  rafIn.writeLong(timePtrs[i]);
  nBytes += 8;
rafIn.writeLong(0l);
rafIn.writeLong(0l);
nBytes += 16l;

代码示例来源:origin: apache/flume

@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);
 }
}

代码示例来源:origin: apache/flume

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);
}

代码示例来源:origin: atomix/atomix

@Override
public Bytes writeLong(int offset, long l) {
 checkWrite(offset, LONG);
 try {
  seekToOffset(offset);
  randomAccessFile.writeLong(l);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return this;
}

代码示例来源:origin: square/tape

@Private static RandomAccessFile initializeFromFile(File file, boolean forceLegacy)
  throws IOException {
 if (!file.exists()) {
  // Use a temp file so we don't leave a partially-initialized file.
  File tempFile = new File(file.getPath() + ".tmp");
  RandomAccessFile raf = open(tempFile);
  try {
   raf.setLength(INITIAL_LENGTH);
   raf.seek(0);
   if (forceLegacy) {
    raf.writeInt(INITIAL_LENGTH);
   } else {
    raf.writeInt(VERSIONED_HEADER);
    raf.writeLong(INITIAL_LENGTH);
   }
  } finally {
   raf.close();
  }
  // A rename is atomic.
  if (!tempFile.renameTo(file)) {
   throw new IOException("Rename failed!");
  }
 }
 return open(file);
}

代码示例来源:origin: apache/activemq

@Override
public void writeLong(long l) throws IOException {
  try {
    getRaf().writeLong(l);
  } catch (IOException ioe) {
    handleException();
    throw ioe;
  }
}

代码示例来源:origin: lealone/Lealone

private synchronized void writeChunkMetaData(int lastChunkId, TreeSet<Long> removedPages) {
  try {
    chunkMetaData.setLength(0);
    chunkMetaData.seek(0);
    chunkMetaData.writeInt(lastChunkId);
    chunkMetaData.writeInt(removedPages.size());
    for (long pos : removedPages) {
      chunkMetaData.writeLong(pos);
    }
    chunkMetaData.writeInt(hashCodeToHostIdMap.size());
    for (String hostId : hashCodeToHostIdMap.values()) {
      chunkMetaData.writeUTF(hostId);
    }
    // chunkMetaData.setLength(4 + 4 + removedPages.size() * 8);
    chunkMetaData.getFD().sync();
  } catch (IOException e) {
    throw panic(DataUtils.newIllegalStateException(DataUtils.ERROR_WRITING_FAILED,
        "Failed to writeChunkMetaData", e));
  }
}

代码示例来源:origin: apache/activemq

randomAccessLockFile.writeLong(System.currentTimeMillis());
randomAccessLockFile.getChannel().force(true);
lastModified = file.lastModified();

代码示例来源:origin: apache/flume

allocate(checkpointFile, totalBytes);
checkpointFileHandle.seek(INDEX_VERSION * Serialization.SIZE_OF_LONG);
checkpointFileHandle.writeLong(getVersion());
checkpointFileHandle.getChannel().force(true);
LOG.info("Preallocated " + checkpointFile + " to " + checkpointFileHandle.length()

代码示例来源:origin: osmdroid/osmdroid

gemfFile.writeInt(range.yMax);
gemfFile.writeInt(range.sourceIndex);
gemfFile.writeLong(range.offset);
for (int x = range.xMin; x < range.xMax + 1; ++x) {
  for (int y = range.yMin; y < range.yMax + 1; ++y) {
    gemfFile.writeLong(offset);
    final long fileSize = dirIndex.get(
        indexSource.get(

代码示例来源:origin: square/tape

@Test public void testSizeLessThanHeaderThrows() throws IOException {
 RandomAccessFile emptyFile = new RandomAccessFile(file, "rwd");
 emptyFile.setLength(INITIAL_LENGTH);
 if (forceLegacy) {
  emptyFile.writeInt(headerLength - 1);
 } else {
  emptyFile.writeInt(0x80000001);
  emptyFile.writeLong(headerLength - 1);
 }
 emptyFile.getChannel().force(true);
 emptyFile.close();
 try {
  newQueueFile();
  fail();
 } catch (IOException ex) {
  assertThat(ex.getMessage()).isIn(
    Arrays.asList("File is corrupt; length stored in header (15) is invalid.",
      "File is corrupt; length stored in header (31) is invalid."));
 }
}

代码示例来源:origin: apache/flume

try {
 checkpointFileHandle.seek(INDEX_VERSION * Serialization.SIZE_OF_LONG);
 checkpointFileHandle.writeLong(Serialization.VERSION_3);
 checkpointFileHandle.getChannel().force(true);
} finally {

代码示例来源:origin: i2p/i2p.i2p

public void writeLong(long v)		throws IOException {  delegate.writeLong(v); }
public void writeFloat(float v)		throws IOException { delegate.writeFloat(v); }

代码示例来源:origin: geotools/geotools

raf.writeLong(address);
raf.writeLong(dataEnd);

代码示例来源:origin: mapsforge/mapsforge

randomAccessFile.writeLong(fileSize);

代码示例来源:origin: geotools/geotools

raf.writeInt((Integer) value);
} else if (binding == Long.class || binding == long.class) {
  raf.writeLong((Long) value);
} else if (binding == Float.class || binding == float.class) {
  raf.writeFloat((Float) value);
    || binding == java.sql.Timestamp.class
    || binding == java.util.Date.class) {
  raf.writeLong(((Date) value).getTime());
} else if (Geometry.class.isAssignableFrom(binding)) {
  WKBWriter writer = new WKBWriter();

相关文章