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

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

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

RandomAccessFile.writeInt介绍

[英]Writes a big-endian 32-bit integer to this file, starting at the current file pointer.
[中]从当前文件指针开始,向该文件写入一个大端32位整数。

代码示例

代码示例来源:origin: GlowstoneMC/Glowstone

private void setOffset(int x, int z, int offset) throws IOException {
  offsets[x + (z << 5)] = offset;
  file.seek((x + (z << 5)) << 2);
  file.writeInt(offset);
}

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

/**
 * Writes a big-endian 32-bit float to this file, starting at the current file pointer.
 * The bytes are those returned by {@link Float#floatToIntBits(float)}, meaning a canonical NaN
 * is used.
 *
 * @param val
 *            the float to write to this file.
 * @throws IOException
 *             if an I/O error occurs while writing to this file.
 * @see #readFloat()
 */
public final void writeFloat(float val) throws IOException {
  writeInt(Float.floatToIntBits(val));
}

代码示例来源:origin: GlowstoneMC/Glowstone

private void setTimestamp(int x, int z, int value) throws IOException {
  chunkTimestamps[x + (z << 5)] = value;
  file.seek(SECTOR_BYTES + ((x + (z << 5)) << 2));
  file.writeInt(value);
}

代码示例来源:origin: google/ExoPlayer

private void writeFileHeader(RandomAccessFile randomAccessFile) throws IOException {
 // Write the start of the header as big endian data.
 randomAccessFile.writeInt(WavUtil.RIFF_FOURCC);
 randomAccessFile.writeInt(-1);
 randomAccessFile.writeInt(WavUtil.WAVE_FOURCC);
 randomAccessFile.writeInt(WavUtil.FMT_FOURCC);
 // Write the rest of the header as little endian data.
 scratchByteBuffer.clear();
 scratchByteBuffer.putInt(16);
 scratchByteBuffer.putShort((short) WavUtil.getTypeForEncoding(encoding));
 scratchByteBuffer.putShort((short) channelCount);
 scratchByteBuffer.putInt(sampleRateHz);
 int bytesPerSample = Util.getPcmFrameSize(encoding, channelCount);
 scratchByteBuffer.putInt(bytesPerSample * sampleRateHz);
 scratchByteBuffer.putShort((short) bytesPerSample);
 scratchByteBuffer.putShort((short) (8 * bytesPerSample / channelCount));
 randomAccessFile.write(scratchBuffer, 0, scratchByteBuffer.position());
 // Write the start of the data chunk as big endian data.
 randomAccessFile.writeInt(WavUtil.DATA_FOURCC);
 randomAccessFile.writeInt(-1);
}

代码示例来源: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: GlowstoneMC/Glowstone

private void writeSector(int sectorNumber, byte[] data, int length) throws IOException {
  file.seek(sectorNumber * SECTOR_BYTES);
  file.writeInt(length + 1); // chunk length
  file.writeByte(VERSION_DEFLATE); // chunk version number
  file.write(data, 0, length); // chunk data
}

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

@Override
public Bytes writeInt(int offset, int i) {
 checkWrite(offset, INTEGER);
 try {
  seekToOffset(offset);
  randomAccessFile.writeInt(i);
 } 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: 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

@Override
public void writeInt(int i) throws IOException {
  try {
    getRaf().writeInt(i);
  } catch (IOException ioe) {
    handleException();
    throw ioe;
  }
}

代码示例来源: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: osmdroid/osmdroid

gemfFile.writeInt(VERSION);
gemfFile.writeInt(TILE_SIZE);
gemfFile.writeInt(sourceIndex.size());
  gemfFile.writeInt(sourceIndex.get(source));
  gemfFile.writeInt(source.length());
  gemfFile.write(source.getBytes());
gemfFile.writeInt(ranges.size());
  gemfFile.writeInt(range.zoom);
  gemfFile.writeInt(range.xMin);
  gemfFile.writeInt(range.xMax);
  gemfFile.writeInt(range.yMin);
  gemfFile.writeInt(range.yMax);
  gemfFile.writeInt(range.sourceIndex);
  gemfFile.writeLong(range.offset);
          indexSource.get(
              range.sourceIndex)).get(range.zoom).get(x).get(y).length();
      gemfFile.writeInt((int)fileSize);
      offset += fileSize;

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

long nBytes = 0;
int numIdx = getNumIdx();
rafIn.writeInt(numIdx);
nBytes += 4;
rafIn.writeInt(idxInterval);
nBytes += 4;
for (int i = 0; i < numIdx; i++) {

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

long nBytes = 0;
int numIdx = getNumIdx();
rafIn.writeInt(numIdx);
nBytes += 4;
rafIn.writeInt(idxInterval);
nBytes += 4;
for (int i = 0; i < numIdx; i++) {

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

@Test public void testNegativeSizeInHeaderThrows() throws IOException {
 RandomAccessFile emptyFile = new RandomAccessFile(file, "rwd");
 emptyFile.seek(0);
 emptyFile.writeInt(-2147483648);
 emptyFile.setLength(INITIAL_LENGTH);
 emptyFile.getChannel().force(true);
 emptyFile.close();
 try {
  newQueueFile();
  fail("Should have thrown about bad header length");
 } catch (IOException ex) {
  assertThat(ex.getMessage()).isIn(
    Arrays.asList("File is corrupt; length stored in header (-2147483648) is invalid.",
      "Unable to read version 0 format. Supported versions are 1 and legacy."));
 }
}

代码示例来源: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: stackoverflow.com

randomAccessWriter.writeInt(0); // Final file size not known yet, write 0 
  randomAccessWriter.writeBytes("WAVE");
  randomAccessWriter.writeBytes("fmt ");
  randomAccessWriter.writeInt(Integer.reverseBytes(16)); // Sub-chunk size, 16 for PCM
  randomAccessWriter.writeShort(Short.reverseBytes((short) 1)); // AudioFormat, 1 for PCM
  randomAccessWriter.writeInt(Integer.reverseBytes(sRate)); // Sample rate
  randomAccessWriter.writeInt(Integer.reverseBytes(sRate*bSamples*nChannels/8)); // Byte rate, SampleRate*NumberOfChannels*BitsPerSample/8
  randomAccessWriter.writeShort(Short.reverseBytes((short)(nChannels*bSamples/8))); // Block align, NumberOfChannels*BitsPerSample/8
  randomAccessWriter.writeInt(0); // Data chunk size not known yet, write 0
randomAccessWriter.writeInt(Integer.reverseBytes(36+payloadSize));
randomAccessWriter.writeInt(Integer.reverseBytes(payloadSize));

代码示例来源:origin: stanfordnlp/CoreNLP

hF.writeInt(x);
fnumArr[x][y]++;

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

public void writeInt(int v)			throws IOException {  delegate.writeInt(v); }
public void writeLong(long v)		throws IOException {  delegate.writeLong(v); }

代码示例来源:origin: ahmetaa/zemberek-nlp

void changeCount(int count) throws IOException {
 try (RandomAccessFile rafw = new RandomAccessFile(file, "rw")) {
  rafw.writeInt(order);
  rafw.writeInt(count);
 }
}

相关文章