Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataBuffer, which is DataOutput to byte[].
I tired of typing ByteArrayOutputStream.
- Loading branch information
1 parent
b2415b8
commit f19a2bf
Showing
3 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
package com.badlogic.gdx.utils; | ||
|
||
import com.badlogic.gdx.utils.StreamUtils.OptimizedByteArrayOutputStream; | ||
|
||
/** Extends {@link DataOutput} that writes bytes to a byte array. | ||
* @author Nathan Sweet */ | ||
public class DataBuffer extends DataOutput { | ||
private final OptimizedByteArrayOutputStream outStream; | ||
|
||
public DataBuffer () { | ||
this(32); | ||
} | ||
|
||
public DataBuffer (int initialSize) { | ||
super(new OptimizedByteArrayOutputStream(initialSize)); | ||
outStream = (OptimizedByteArrayOutputStream)out; | ||
} | ||
|
||
/** Returns the backing array, which has 0 to {@link #size()} items. */ | ||
public byte[] getBuffer () { | ||
return outStream.getBuffer(); | ||
} | ||
|
||
public byte[] toArray () { | ||
return outStream.toByteArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters