C# Class fNbt.NbtWriter

An efficient writer for writing NBT data directly to streams. Each instance of NbtWriter writes one complete file. NbtWriter enforces all constraints of the NBT file format EXCEPT checking for duplicate tag names within a compound.
Afficher le fichier Open project: fragmer/fNbt Class Usage Examples

Private Properties

Свойство Type Description
CheckArray void
EnforceConstraints void
GoDown void
GoUp void
WriteByteArrayFromStreamImpl void

Méthodes publiques

Méthode Description
BeginCompound ( ) : void

Begins an unnamed compound tag.

BeginCompound ( [ tagName ) : void

Begins a named compound tag.

BeginList ( NbtTagType elementType, int size ) : void

Begins an unnamed list tag.

BeginList ( [ tagName, NbtTagType elementType, int size ) : void

Begins an unnamed list tag.

EndCompound ( ) : void

Ends a compound tag.

EndList ( ) : void

Ends a list tag.

Finish ( ) : void

Ensures that file has been written in its entirety, with no tags left open. This method is for verification only, and does not actually write any data. Calling this method is optional (but probably a good idea, to catch any usage errors).

NbtWriter ( [ stream, [ rootTagName ) : System

Initializes a new instance of the NbtWriter class.

Assumes that data in the stream should be Big-Endian encoded.

NbtWriter ( [ stream, [ rootTagName, bool bigEndian ) : System

Initializes a new instance of the NbtWriter class.

WriteByte ( [ tagName, byte value ) : void

Writes an unnamed byte tag.

WriteByte ( byte value ) : void

Writes an unnamed byte tag.

WriteByteArray ( [ data ) : void

Writes an unnamed byte array tag, copying data from an array.

WriteByteArray ( [ tagName, [ data ) : void

Writes a named byte array tag, copying data from an array.

WriteByteArray ( [ tagName, [ dataSource, int count ) : void

Writes a named byte array tag, copying data from a stream.

A temporary buffer will be allocated, of size up to 8192 bytes. To manually specify a buffer, use one of the other WriteByteArray() overloads.

WriteByteArray ( [ tagName, [ dataSource, int count, [ buffer ) : void

Writes an unnamed byte array tag, copying data from another stream.

WriteByteArray ( [ tagName, [ data, int offset, int count ) : void

Writes a named byte array tag, copying data from an array.

WriteByteArray ( [ dataSource, int count ) : void

Writes an unnamed byte array tag, copying data from a stream.

A temporary buffer will be allocated, of size up to 8192 bytes. To manually specify a buffer, use one of the other WriteByteArray() overloads.

WriteByteArray ( [ dataSource, int count, [ buffer ) : void

Writes an unnamed byte array tag, copying data from a stream.

WriteByteArray ( [ data, int offset, int count ) : void

Writes an unnamed byte array tag, copying data from an array.

WriteDouble ( [ tagName, double value ) : void

Writes an unnamed byte tag.

WriteDouble ( double value ) : void

Writes an unnamed double tag.

WriteFloat ( [ tagName, float value ) : void

Writes an unnamed float tag.

WriteFloat ( float value ) : void

Writes an unnamed float tag.

WriteInt ( [ tagName, int value ) : void

Writes an unnamed int tag.

WriteInt ( int value ) : void

Writes an unnamed int tag.

WriteIntArray ( [ data ) : void

Writes an unnamed int array tag, copying data from an array.

WriteIntArray ( [ tagName, [ data ) : void

Writes a named int array tag, copying data from an array.

WriteIntArray ( [ tagName, [ data, int offset, int count ) : void

Writes a named int array tag, copying data from an array.

WriteIntArray ( [ data, int offset, int count ) : void

Writes an unnamed int array tag, copying data from an array.

WriteLong ( [ tagName, long value ) : void

Writes an unnamed long tag.

WriteLong ( long value ) : void

Writes an unnamed long tag.

WriteShort ( [ tagName, short value ) : void

Writes an unnamed short tag.

WriteShort ( short value ) : void

Writes an unnamed short tag.

WriteString ( [ value ) : void

Writes an unnamed string tag.

WriteString ( [ tagName, [ value ) : void

Writes an unnamed string tag.

WriteTag ( [ tag ) : void

Writes a NbtTag object, and all of its child tags, to stream. Use this method sparingly with NbtWriter -- constructing NbtTag objects defeats the purpose of this class. If you already have lots of NbtTag objects, you might as well use NbtFile to write them all at once.

Private Methods

Méthode Description
CheckArray ( [ data, int offset, int count ) : void
EnforceConstraints ( [ name, NbtTagType desiredType ) : void
GoDown ( NbtTagType thisType ) : void
GoUp ( ) : void
WriteByteArrayFromStreamImpl ( [ dataSource, int count, [ buffer ) : void

Method Details

BeginCompound() public méthode

Begins an unnamed compound tag.
No more tags can be written -OR- /// a named compound tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded.
public BeginCompound ( ) : void
Résultat void

BeginCompound() public méthode

Begins a named compound tag.
No more tags can be written -OR- /// an unnamed compound tag was expected -OR- a tag of a different type was expected.
public BeginCompound ( [ tagName ) : void
tagName [ Name to give to this compound tag. May not be null.
Résultat void

BeginList() public méthode

Begins an unnamed list tag.
No more tags can be written -OR- /// a named list tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded. is negative -OR- /// is not a valid NbtTagType.
public BeginList ( NbtTagType elementType, int size ) : void
elementType NbtTagType Type of elements of this list.
size int Number of elements in this list. Must not be negative.
Résultat void

BeginList() public méthode

Begins an unnamed list tag.
No more tags can be written -OR- /// an unnamed list tag was expected -OR- a tag of a different type was expected. is negative -OR- /// is not a valid NbtTagType.
public BeginList ( [ tagName, NbtTagType elementType, int size ) : void
tagName [ Name to give to this compound tag. May not be null.
elementType NbtTagType Type of elements of this list.
size int Number of elements in this list. Must not be negative.
Résultat void

EndCompound() public méthode

Ends a compound tag.
Not currently in a compound.
public EndCompound ( ) : void
Résultat void

EndList() public méthode

Ends a list tag.
Not currently in a list -OR- /// not all list elements have been written yet.
public EndList ( ) : void
Résultat void

Finish() public méthode

Ensures that file has been written in its entirety, with no tags left open. This method is for verification only, and does not actually write any data. Calling this method is optional (but probably a good idea, to catch any usage errors).
Not all tags have been closed yet.
public Finish ( ) : void
Résultat void

NbtWriter() public méthode

Initializes a new instance of the NbtWriter class.
Assumes that data in the stream should be Big-Endian encoded.
or is null. is not writable.
public NbtWriter ( [ stream, [ rootTagName ) : System
stream [ Stream to write to.
rootTagName [ Name to give to the root tag (written immediately).
Résultat System

NbtWriter() public méthode

Initializes a new instance of the NbtWriter class.
or is null. is not writable.
public NbtWriter ( [ stream, [ rootTagName, bool bigEndian ) : System
stream [ Stream to write to.
rootTagName [ Name to give to the root tag (written immediately).
bigEndian bool Whether NBT data should be in Big-Endian encoding.
Résultat System

WriteByte() public méthode

Writes an unnamed byte tag.
No more tags can be written -OR- /// an unnamed byte tag was expected -OR- a tag of a different type was expected.
public WriteByte ( [ tagName, byte value ) : void
tagName [ Name to give to this compound tag. May not be null.
value byte The unsigned byte to write.
Résultat void

WriteByte() public méthode

Writes an unnamed byte tag.
No more tags can be written -OR- /// a named byte tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded.
public WriteByte ( byte value ) : void
value byte The unsigned byte to write.
Résultat void

WriteByteArray() public méthode

Writes an unnamed byte array tag, copying data from an array.
No more tags can be written -OR- /// a named byte array tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded. is null
public WriteByteArray ( [ data ) : void
data [ A byte array containing the data to write.
Résultat void

WriteByteArray() public méthode

Writes a named byte array tag, copying data from an array.
No more tags can be written -OR- /// an unnamed byte array tag was expected -OR- a tag of a different type was expected. or /// is null
public WriteByteArray ( [ tagName, [ data ) : void
tagName [ Name to give to this byte array tag. May not be null.
data [ A byte array containing the data to write.
Résultat void

WriteByteArray() public méthode

Writes a named byte array tag, copying data from a stream.
A temporary buffer will be allocated, of size up to 8192 bytes. To manually specify a buffer, use one of the other WriteByteArray() overloads.
No more tags can be written -OR- /// an unnamed byte array tag was expected -OR- a tag of a different type was expected. is negative. is null. Given stream does not support reading.
public WriteByteArray ( [ tagName, [ dataSource, int count ) : void
tagName [ Name to give to this byte array tag. May not be null.
dataSource [ A Stream from which data will be copied.
count int The number of bytes to write. Must not be negative.
Résultat void

WriteByteArray() public méthode

Writes an unnamed byte array tag, copying data from another stream.
No more tags can be written -OR- /// an unnamed byte array tag was expected -OR- a tag of a different type was expected. is negative. is null. Given stream does not support reading -OR- /// size is 0.
public WriteByteArray ( [ tagName, [ dataSource, int count, [ buffer ) : void
tagName [ Name to give to this byte array tag. May not be null.
dataSource [ A Stream from which data will be copied.
count int The number of bytes to write. Must not be negative.
buffer [ Buffer to use for copying. Size must be greater than 0. Must not be null.
Résultat void

WriteByteArray() public méthode

Writes a named byte array tag, copying data from an array.
No more tags can be written -OR- /// an unnamed byte array tag was expected -OR- a tag of a different type was expected. or /// is negative. or /// is null is greater than /// subtracted from the array length.
public WriteByteArray ( [ tagName, [ data, int offset, int count ) : void
tagName [ Name to give to this byte array tag. May not be null.
data [ A byte array containing the data to write.
offset int The starting point in at which to begin writing. Must not be negative.
count int The number of bytes to write. Must not be negative.
Résultat void

WriteByteArray() public méthode

Writes an unnamed byte array tag, copying data from a stream.
A temporary buffer will be allocated, of size up to 8192 bytes. To manually specify a buffer, use one of the other WriteByteArray() overloads.
No more tags can be written -OR- /// a named byte array tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded. is negative. is null. Given stream does not support reading.
public WriteByteArray ( [ dataSource, int count ) : void
dataSource [ A Stream from which data will be copied.
count int The number of bytes to write. Must not be negative.
Résultat void

WriteByteArray() public méthode

Writes an unnamed byte array tag, copying data from a stream.
No more tags can be written -OR- /// a named byte array tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded. is negative. is null. Given stream does not support reading -OR- /// size is 0.
public WriteByteArray ( [ dataSource, int count, [ buffer ) : void
dataSource [ A Stream from which data will be copied.
count int The number of bytes to write. Must not be negative.
buffer [ Buffer to use for copying. Size must be greater than 0. Must not be null.
Résultat void

WriteByteArray() public méthode

Writes an unnamed byte array tag, copying data from an array.
No more tags can be written -OR- /// a named byte array tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded. or /// is negative. is null is greater than /// subtracted from the array length.
public WriteByteArray ( [ data, int offset, int count ) : void
data [ A byte array containing the data to write.
offset int The starting point in at which to begin writing. Must not be negative.
count int The number of bytes to write. Must not be negative.
Résultat void

WriteDouble() public méthode

Writes an unnamed byte tag.
No more tags can be written -OR- /// an unnamed byte tag was expected -OR- a tag of a different type was expected.
public WriteDouble ( [ tagName, double value ) : void
tagName [ Name to give to this compound tag. May not be null.
value double The unsigned byte to write.
Résultat void

WriteDouble() public méthode

Writes an unnamed double tag.
No more tags can be written -OR- /// a named double tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded.
public WriteDouble ( double value ) : void
value double The eight-byte floating-point value to write.
Résultat void

WriteFloat() public méthode

Writes an unnamed float tag.
No more tags can be written -OR- /// an unnamed float tag was expected -OR- a tag of a different type was expected.
public WriteFloat ( [ tagName, float value ) : void
tagName [ Name to give to this compound tag. May not be null.
value float The four-byte floating-point value to write.
Résultat void

WriteFloat() public méthode

Writes an unnamed float tag.
No more tags can be written -OR- /// a named float tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded.
public WriteFloat ( float value ) : void
value float The four-byte floating-point value to write.
Résultat void

WriteInt() public méthode

Writes an unnamed int tag.
No more tags can be written -OR- /// an unnamed int tag was expected -OR- a tag of a different type was expected.
public WriteInt ( [ tagName, int value ) : void
tagName [ Name to give to this compound tag. May not be null.
value int The four-byte signed integer to write.
Résultat void

WriteInt() public méthode

Writes an unnamed int tag.
No more tags can be written -OR- /// a named int tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded.
public WriteInt ( int value ) : void
value int The four-byte signed integer to write.
Résultat void

WriteIntArray() public méthode

Writes an unnamed int array tag, copying data from an array.
No more tags can be written -OR- /// a named int array tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded. is null
public WriteIntArray ( [ data ) : void
data [ An int array containing the data to write.
Résultat void

WriteIntArray() public méthode

Writes a named int array tag, copying data from an array.
No more tags can be written -OR- /// an unnamed int array tag was expected -OR- a tag of a different type was expected. or /// is null
public WriteIntArray ( [ tagName, [ data ) : void
tagName [ Name to give to this int array tag. May not be null.
data [ An int array containing the data to write.
Résultat void

WriteIntArray() public méthode

Writes a named int array tag, copying data from an array.
No more tags can be written -OR- /// an unnamed int array tag was expected -OR- a tag of a different type was expected. or /// is negative. or /// is null is greater than /// subtracted from the array length.
public WriteIntArray ( [ tagName, [ data, int offset, int count ) : void
tagName [ Name to give to this int array tag. May not be null.
data [ An int array containing the data to write.
offset int The starting point in at which to begin writing. Must not be negative.
count int The number of elements to write. Must not be negative.
Résultat void

WriteIntArray() public méthode

Writes an unnamed int array tag, copying data from an array.
No more tags can be written -OR- /// a named int array tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded. or /// is negative. is null is greater than /// subtracted from the array length.
public WriteIntArray ( [ data, int offset, int count ) : void
data [ An int array containing the data to write.
offset int The starting point in at which to begin writing. Must not be negative.
count int The number of elements to write. Must not be negative.
Résultat void

WriteLong() public méthode

Writes an unnamed long tag.
No more tags can be written -OR- /// an unnamed long tag was expected -OR- a tag of a different type was expected.
public WriteLong ( [ tagName, long value ) : void
tagName [ Name to give to this compound tag. May not be null.
value long The eight-byte signed integer to write.
Résultat void

WriteLong() public méthode

Writes an unnamed long tag.
No more tags can be written -OR- /// a named long tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded.
public WriteLong ( long value ) : void
value long The eight-byte signed integer to write.
Résultat void

WriteShort() public méthode

Writes an unnamed short tag.
No more tags can be written -OR- /// an unnamed short tag was expected -OR- a tag of a different type was expected.
public WriteShort ( [ tagName, short value ) : void
tagName [ Name to give to this compound tag. May not be null.
value short The two-byte signed integer to write.
Résultat void

WriteShort() public méthode

Writes an unnamed short tag.
No more tags can be written -OR- /// a named short tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded.
public WriteShort ( short value ) : void
value short The two-byte signed integer to write.
Résultat void

WriteString() public méthode

Writes an unnamed string tag.
No more tags can be written -OR- /// a named string tag was expected -OR- a tag of a different type was expected -OR- /// the size of a parent list has been exceeded.
public WriteString ( [ value ) : void
value [ The string to write.
Résultat void

WriteString() public méthode

Writes an unnamed string tag.
No more tags can be written -OR- /// an unnamed string tag was expected -OR- a tag of a different type was expected.
public WriteString ( [ tagName, [ value ) : void
tagName [ Name to give to this compound tag. May not be null.
value [ The string to write.
Résultat void

WriteTag() public méthode

Writes a NbtTag object, and all of its child tags, to stream. Use this method sparingly with NbtWriter -- constructing NbtTag objects defeats the purpose of this class. If you already have lots of NbtTag objects, you might as well use NbtFile to write them all at once.
No more tags can be written -OR- given tag is unacceptable at this time. is null
public WriteTag ( [ tag ) : void
tag [ Tag to write. Must not be null.
Résultat void