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

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

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

RandomAccessFile.writeByte介绍

[英]Writes an 8-bit byte to this file, starting at the current file pointer. Only the least significant byte of the integer val is written.
[中]从当前文件指针开始,向该文件写入8位字节。只写入整数val的最低有效字节。

代码示例

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

public void open(File outputFile) throws IOException {
  outputFile.mkdirs();
  if (outputFile.exists()) {
    outputFile.delete();
  }
  outputFile.createNewFile();
  outputRAF = new RandomAccessFile(outputFile, "rw");
  outputRAF.setLength(mappedFileSizeBytes);
  outputRAF.seek(mappedFileSizeBytes - 1);
  outputRAF.writeByte(0);
  outputRAF.seek(0);
  outputChannel = outputRAF.getChannel();
  fileBuffer = outputChannel.map(FileChannel.MapMode.READ_WRITE, 0, mappedFileSizeBytes);
}

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

@SuppressWarnings("unchecked")
public void open(File inputFile) throws IOException {
  deserializer = (Deserializer<OUT>) (readAsByteArray ? new ByteArrayDeserializer() : new TupleDeserializer());
  inputFile.getParentFile().mkdirs();
  if (inputFile.exists()) {
    inputFile.delete();
  }
  inputFile.createNewFile();
  inputRAF = new RandomAccessFile(inputFile, "rw");
  inputRAF.setLength(mappedFileSizeBytes);
  inputRAF.seek(mappedFileSizeBytes - 1);
  inputRAF.writeByte(0);
  inputRAF.seek(0);
  inputChannel = inputRAF.getChannel();
  fileBuffer = inputChannel.map(FileChannel.MapMode.READ_WRITE, 0, mappedFileSizeBytes);
}

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

public void markRecordAsNoop(long offset) throws IOException {
 // First ensure that the offset actually is an OP_RECORD. There is a
 // small possibility that it still is OP_RECORD,
 // but is not actually the beginning of a record. Is there anything we
 // can do about it?
 fileHandle.seek(offset);
 byte byteRead = fileHandle.readByte();
 Preconditions.checkState(byteRead == OP_RECORD || byteRead == OP_NOOP,
   "Expected to read a record but the byte read indicates EOF");
 fileHandle.seek(offset);
 LOG.info("Marking event as " + OP_NOOP + " at " + offset + " for file " +
   file.toString());
 fileHandle.writeByte(OP_NOOP);
}

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

@Override
public Bytes writeByte(int offset, int b) {
 checkWrite(offset, BYTE);
 try {
  seekToOffset(offset);
  randomAccessFile.writeByte(b);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return this;
}

代码示例来源:origin: smuyyh/BookReader

byte temp = raf.readByte();
raf.seek(i);
raf.writeByte(temp);

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

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

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

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

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

public void writeByte(int v)		throws IOException { delegate.writeByte(v); }
public void writeShort(int v)		throws IOException { delegate.writeShort(v); }

代码示例来源:origin: yacy/yacy_grid_mcp

public void add(final String key) throws IOException {
  if (this.keys.containsKey(key)) return;
  synchronized (this.raf) {
    if (this.keys.containsKey(key)) return; // check again for those threads who come late (after another has written this)
    this.keys.put(key, _obj);
    this.raf.seek(this.raf.length());
    this.raf.write(key.getBytes(StandardCharsets.UTF_8));
    this.raf.writeByte('\n');
  }
}

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

raf.writeBoolean((Boolean) value);
} else if (binding == Byte.class || binding == byte.class) {
  raf.writeByte((Byte) value);
} else if (binding == Short.class || binding == short.class) {
  raf.writeShort((Short) value);

代码示例来源:origin: net.imagej/ij

public void write (int b) throws IOException {
  //IJ.log("stream: byte");
  raFile.writeByte(b); //just for completeness, usually not used by image encoders
}
public void write (byte[] b) throws IOException {

代码示例来源:origin: dk.eobjects.metamodel/MetaModel-dbase

public DBT_fpt(DBF iDBF, String name, boolean destroy) throws IOException,
    xBaseJException {
  super(iDBF, name, destroy, DBF.FOXPRO_WITH_MEMO);
  nextBlock = 8;
  file.writeInt(nextBlock);
  file.writeByte(0);
  file.writeByte(0);
  memoBlockSize = 64;
  file.writeShort(memoBlockSize);
  for (int i = 0; i < 504; i += 4)
    file.writeInt(0);
}

代码示例来源:origin: org.mapdb/mapdb

@Override
public synchronized void putByte(long offset, byte value) {
  if (CC.VOLUME_PRINT_STACK_AT_OFFSET != 0 && CC.VOLUME_PRINT_STACK_AT_OFFSET == offset) {
    new IOException("VOL STACK:").printStackTrace();
  }
  try {
    raf.seek(offset);
    raf.writeByte(value);
  } catch (IOException e) {
    throw new DBException.VolumeIOError(e);
  }
}

代码示例来源:origin: org.eobjects.metamodel-extras/MetaModel-extras-dbase

public void setNextBlock() throws IOException {
  if (file.length() == 0) {
    file.writeInt(DbaseUtils.x86(1));
    nextBlock = 1;
    file.seek(511);
    file.writeByte(0);
  } else {
    nextBlock = DbaseUtils.x86(file.readInt());
  }
}

代码示例来源:origin: org.eobjects.metamodel-extras/MetaModel-extras-dbase

public DBT_iv(DBF iDBF, String name, boolean destroy) throws IOException,
    xBaseJException {
  super(iDBF, name, destroy, DBF.DBASEIV_WITH_MEMO);
  nextBlock = 1;
  file.writeInt(DbaseUtils.x86(nextBlock));
  for (int i = 0; i < 16; i++)
    file.writeByte(0);
  memoBlockSize = 512;
  file.writeInt(DbaseUtils.x86(memoBlockSize));
}

代码示例来源:origin: org.onosproject/onlab-thirdparty

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

代码示例来源:origin: io.atomix/catalyst-buffer

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

代码示例来源:origin: org.apache.activemq/activemq-kahadb-store

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

代码示例来源:origin: octo-online/reactive-audit

@Test(expected = FileReactiveAuditException.class)
public void writeByte()
    throws IOException
{
  ReactiveAudit.off.commit();
  try (RandomAccessFile rw = newRandomAccessFile())
  {
    TestTools.strict.commit();
    rw.writeByte(0);
  }
}

相关文章