Show / Hide Table of Contents

Class DataWriter

BinaryWriter extension that adds methods for writing 32 and 64-bit integer values in a packed format.

Inheritance
System.Object
System.IO.BinaryWriter
DataWriter
Implements
System.IDisposable
Inherited Members
System.IO.BinaryWriter.Null
System.IO.BinaryWriter.OutStream
System.IO.BinaryWriter.Dispose()
System.IO.BinaryWriter.Dispose(System.Boolean)
System.IO.BinaryWriter.Flush()
System.IO.BinaryWriter.Seek(System.Int32, System.IO.SeekOrigin)
System.IO.BinaryWriter.Write(System.Boolean)
System.IO.BinaryWriter.Write(System.Byte)
System.IO.BinaryWriter.Write(System.Byte[])
System.IO.BinaryWriter.Write(System.Byte[], System.Int32, System.Int32)
System.IO.BinaryWriter.Write(System.Char)
System.IO.BinaryWriter.Write(System.Char[])
System.IO.BinaryWriter.Write(System.Char[], System.Int32, System.Int32)
System.IO.BinaryWriter.Write(System.Decimal)
System.IO.BinaryWriter.Write(System.SByte)
System.IO.BinaryWriter.Write7BitEncodedInt(System.Int32)
System.IO.BinaryWriter.BaseStream
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Tangosol.IO
Assembly: Coherence.Core.dll
Syntax
public class DataWriter : BinaryWriter, IDisposable
Remarks

The "packed" format includes a sign bit (0x40) and a continuation bit (0x80) in the first byte, followed by the least 6 significant bits of the int value. Subsequent bytes (each appearing only if the previous byte had its continuation bit set) include a continuation bit (0x80) and the next least 7 significant bits of the int value.

In this way, a 32-bit value is encoded into 1-5 bytes, and 64-bit value is encoded into 1-10 bytes, depending on the magnitude of the value being encoded.

Constructors

| Improve this Doc View Source

DataWriter(Stream)

Construct a new DataWriter that will write data to the specified Stream object.

Declaration
public DataWriter(Stream output)
Parameters
Type Name Description
System.IO.Stream output

The Stream object to write to; must not be null.

Fields

| Improve this Doc View Source

CHAR_BUF_MASK

Bitmask used against a raw offset to determine the offset within the temporary character buffer.

Declaration
protected const int CHAR_BUF_MASK = 255
Field Value
Type Description
System.Int32
| Improve this Doc View Source

CHAR_BUF_SIZE

Size of the temporary character buffer. Must be a power of 2. Size is: 256 characters (.25 KB).

Declaration
protected const int CHAR_BUF_SIZE = 256
Field Value
Type Description
System.Int32
| Improve this Doc View Source

m_achBuf

A lazily instantiated temp buffer used to avoid allocations from and repeated calls to String functions.

Declaration
protected char[] m_achBuf
Field Value
Type Description
System.Char[]

Properties

| Improve this Doc View Source

CharBuf

Obtain a temp buffer used to avoid allocations from repeated calls to String APIs.

Declaration
protected char[] CharBuf { get; }
Property Value
Type Description
System.Char[]

Methods

| Improve this Doc View Source

CalcUTF(String)

Figure out how many bytes it will take to hold the passed String.

Declaration
protected int CalcUTF(string s)
Parameters
Type Name Description
System.String s

the String

Returns
Type Description
System.Int32
Remarks

This method is tightly bound to formatUTF.

| Improve this Doc View Source

FormatUTF(Byte[], Int32, Char[], Int32)

Format the passed characters as UTF into the passed byte array.

Declaration
protected int FormatUTF(byte[] ab, int ofb, char[] ach, int cch)
Parameters
Type Name Description
System.Byte[] ab

The byte array to format into.

System.Int32 ofb

The offset into the byte array to write the first byte.

System.Char[] ach

The array of characters to format.

System.Int32 cch

The number of characters to format.

Returns
Type Description
System.Int32
| Improve this Doc View Source

FormatUTF(String)

Format the passed String as UTF into the passed byte array.

Declaration
public byte[] FormatUTF(string s)
Parameters
Type Name Description
System.String s

the string.

Returns
Type Description
System.Byte[]

The formated UTF byte array.

Remarks

This method is tightly bound to calcUTF.

| Improve this Doc View Source

Tmpbuf(Int32)

Get a buffer for formating data to bytes. Note that the resulting buffer may be shorter than the requested size.

Declaration
protected byte[] Tmpbuf(int cb)
Parameters
Type Name Description
System.Int32 cb

the requested size for the buffer

Returns
Type Description
System.Byte[]
| Improve this Doc View Source

Write(Double)

Converts a Double value to its bits and writes an Int64 instance which stores the bits.

Declaration
public override void Write(double value)
Parameters
Type Name Description
System.Double value

A Double value to write.

Overrides
System.IO.BinaryWriter.Write(System.Double)
| Improve this Doc View Source

Write(Int16)

Writes a two-byte signed integer to the current stream and advances the stream position by two bytes.

Declaration
public override void Write(short value)
Parameters
Type Name Description
System.Int16 value

The two-byte signed integer to write.

Overrides
System.IO.BinaryWriter.Write(System.Int16)
Remarks

Overrides BinaryWriter.Write(Int16) by changing endian of the value written to the stream.

| Improve this Doc View Source

Write(Int32)

Writes a four-byte signed integer to the current stream and advances the stream position by four bytes.

Declaration
public override void Write(int value)
Parameters
Type Name Description
System.Int32 value

The four-byte signed integer to write.

Overrides
System.IO.BinaryWriter.Write(System.Int32)
Remarks

Overrides BinaryWriter.Write(Int32) by changing endian of the value written to the stream.

| Improve this Doc View Source

Write(Int64)

Writes a eight-byte signed integer to the current stream and advances the stream position by eight bytes.

Declaration
public override void Write(long value)
Parameters
Type Name Description
System.Int64 value

The eight-byte signed integer to write.

Overrides
System.IO.BinaryWriter.Write(System.Int64)
Remarks

Overrides BinaryWriter.Write(Int64) by changing endian of the value written to the stream.

| Improve this Doc View Source

Write(Single)

Converts a Single value to its bits and writes an Int32 instance which stores the bits.

Declaration
public override void Write(float value)
Parameters
Type Name Description
System.Single value

A Single value to write.

Overrides
System.IO.BinaryWriter.Write(System.Single)
| Improve this Doc View Source

Write(String)

Writes string to the stream prefixed by its length in "packed" format.

Declaration
public override void Write(string text)
Parameters
Type Name Description
System.String text

A string to write.

Overrides
System.IO.BinaryWriter.Write(System.String)
| Improve this Doc View Source

Write(UInt16)

Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes.

Declaration
public override void Write(ushort value)
Parameters
Type Name Description
System.UInt16 value

The two-byte unsigned integer to write.

Overrides
System.IO.BinaryWriter.Write(System.UInt16)
Remarks

Overrides BinaryWriter.Write(UInt16) by changing endian of the value written to the stream.

| Improve this Doc View Source

Write(UInt32)

Writes a four-byte unsigned integer to the current stream and advances the stream position by four bytes.

Declaration
public override void Write(uint value)
Parameters
Type Name Description
System.UInt32 value

The four-byte unsigned integer to write.

Overrides
System.IO.BinaryWriter.Write(System.UInt32)
Remarks

Overrides BinaryWriter.Write(UInt32) by changing endian of the value written to the stream.

| Improve this Doc View Source

Write(UInt64)

Writes a eight-byte unsigned integer to the current stream and advances the stream position by eight bytes.

Declaration
public override void Write(ulong value)
Parameters
Type Name Description
System.UInt64 value

The eight-byte unsigned integer to write.

Overrides
System.IO.BinaryWriter.Write(System.UInt64)
Remarks

Overrides BinaryWriter.Write(UInt64) by changing endian of the value written to the stream.

| Improve this Doc View Source

WritePackedInt32(Int32)

Write an Int32 value using a variable-length storage format.

Declaration
public virtual void WritePackedInt32(int n)
Parameters
Type Name Description
System.Int32 n

An Int32 value to write.

Remarks

The "packed" format includes a sign bit (0x40) and a continuation bit (0x80) in the first byte, followed by the least 6 significant bits of the int value. Subsequent bytes (each appearing only if the previous byte had its continuation bit set) include a continuation bit (0x80) and the next least 7 significant bits of the int value. In this way, a 32-bit value is encoded into 1-5 bytes, depending on the magnitude of the value being encoded.

Exceptions
Type Condition
System.IO.IOException

If an I/O error occurs.

| Improve this Doc View Source

WritePackedInt64(Int64)

Write an Int64 value using a variable-length storage format.

Declaration
public virtual void WritePackedInt64(long l)
Parameters
Type Name Description
System.Int64 l

An Int64 value to write.

Remarks

The "packed" format includes a sign bit (0x40) and a continuation bit (0x80) in the first byte, followed by the least 6 significant bits of the long value. Subsequent bytes (each appearing only if the previous byte had its continuation bit set) include a continuation bit (0x80) and the next least 7 significant bits of the long value. In this way, a 64-bit value is encoded into 1-10 bytes, depending on the magnitude of the value being encoded.

Exceptions
Type Condition
System.IO.IOException

If an I/O error occurs.

| Improve this Doc View Source

WritePackedRawInt128(DataWriter, RawInt128)

Write a RawInt128 value to DataWriter.

Declaration
public virtual void WritePackedRawInt128(DataWriter writer, RawInt128 rawInt128)
Parameters
Type Name Description
DataWriter writer

The DataWriter to write to.

RawInt128 rawInt128

RawInt128 value.

Remarks

RawInt128 value, which is represented as array of signed bytes.

Implements

System.IDisposable

See Also

DataReader
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2000, 2020, Oracle and/or its affiliates. All rights reserved.