BinaryWriter (object)

バージョン 1.12.0 で追加.

The BinaryWriter is used to write binary data to files. It supports writing of any shallow data structure represented as a Data pointer and a DataSize.

BinaryWriter BinaryWriter BinaryWriter FileWriter FileWriter BinaryWriter->FileWriter

/*
** Example: BinaryWriter
*/

require FileIO;
  
operator entry() {

  FilePath path = FilePath('${TEMP}/binaryWriter.bin').expandEnvVars();
  {
    BinaryWriter writer = BinaryWriter(path.string());
    Size count = 50;
    Scalar values[];
    values.resize(count);
    for(Size i=0;i<values.size();i++)
      values[i] = Scalar(i) * 0.7;
    report(values[3]);
    report(values[17]);
    report(values[33]);
  
    writer.write(count.data(), count.dataSize());
    writer.write(values.data(), values.dataSize());
    report('Binary file written.');
  }
  
}

/*
** Output:

+2.1
+11.9
+23.1
Binary file written.

*/

Methods

  BinaryWriter ( in BinaryWriter other )
  BinaryWriter ( in String filePath )
  BinaryWriter ()
BinaryWriter clone ? ()
Boolean close ! ()
Boolean isOpen ? ()
Boolean open ! ( in String filePath )
UInt64 pos ! ()
  seek ! ( in UInt64 pos )
  write ! ( in Data data, in UInt64 dataSize )
  writeString ! ( in String string )
  writeStringArray ! ( in String strings[] )
  ~BinaryWriter ()

Methods in detail

BinaryWriter ( in BinaryWriter other )

copy constructor


BinaryWriter ( in String filePath )

constructs a new writer object with a given filePath


BinaryWriter ()

standard constructor


BinaryWriter BinaryWriter.clone? ()

clone method


Boolean BinaryWriter.close! ()

closes a currently opened file, returns true if successful


Boolean BinaryWriter.isOpen? ()

returns true if the file is currently open


Boolean BinaryWriter.open! ( in String filePath )

opens a new writable file, returns true if successful


UInt64 BinaryWriter.pos! ()

returns the position in the file


BinaryWriter.seek! ( in UInt64 pos )

Set position in output sequence


BinaryWriter.write! ( in Data data, in UInt64 dataSize )

writes the content of the string into the file


BinaryWriter.writeString! ( in String string )

writes a single string to the stream


BinaryWriter.writeStringArray! ( in String strings[] )

write an array of string to the stream


~ BinaryWriter ()

standard destructor