|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
package com.fastasyncworldedit.core.internal.io;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
|
|
|
|
|
import java.io.DataOutput;
|
|
|
|
|
import java.io.FilterOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
@ -19,8 +18,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* Creates a new little endian output stream and chains it to the
|
|
|
|
|
* output stream specified by the out argument.
|
|
|
|
|
*
|
|
|
|
|
* @param out the underlying output stream.
|
|
|
|
|
* @see FilterOutputStream#out
|
|
|
|
|
* @param out the underlying output stream.
|
|
|
|
|
* @see FilterOutputStream#out
|
|
|
|
|
*/
|
|
|
|
|
public LittleEndianOutputStream(OutputStream out) {
|
|
|
|
|
super(out);
|
|
|
|
@ -29,8 +28,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
/**
|
|
|
|
|
* Writes the specified byte value to the underlying output stream.
|
|
|
|
|
*
|
|
|
|
|
* @param b the {@code byte} value to be written.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @param b the {@code byte} value to be written.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public synchronized void write(int b) throws IOException {
|
|
|
|
@ -42,10 +41,10 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* Writes {@code length} bytes from the specified byte array
|
|
|
|
|
* starting at {@code offset} to the underlying output stream.
|
|
|
|
|
*
|
|
|
|
|
* @param data the data.
|
|
|
|
|
* @param offset the start offset in the data.
|
|
|
|
|
* @param length the number of bytes to write.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @param data the data.
|
|
|
|
|
* @param offset the start offset in the data.
|
|
|
|
|
* @param length the number of bytes to write.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public synchronized void write(@Nonnull byte[] data, int offset, int length)
|
|
|
|
@ -60,8 +59,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* a single byte. If the argument is true, the byte value 1 is written.
|
|
|
|
|
* If the argument is false, the byte value {@code 0} in written.
|
|
|
|
|
*
|
|
|
|
|
* @param b the {@code boolean} value to be written.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @param b the {@code boolean} value to be written.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void writeBoolean(boolean b) throws IOException {
|
|
|
|
@ -77,8 +76,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
/**
|
|
|
|
|
* Writes out a {@code byte} to the underlying output stream
|
|
|
|
|
*
|
|
|
|
|
* @param b the {@code byte} value to be written.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @param b the {@code byte} value to be written.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void writeByte(int b) throws IOException {
|
|
|
|
@ -90,8 +89,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* Writes a two byte {@code short} to the underlying output stream in
|
|
|
|
|
* little endian order, low byte first.
|
|
|
|
|
*
|
|
|
|
|
* @param s the {@code short} to be written.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @param s the {@code short} to be written.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void writeShort(int s) throws IOException {
|
|
|
|
@ -106,8 +105,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* Writes a two byte {@code char} to the underlying output stream
|
|
|
|
|
* in little endian order, low byte first.
|
|
|
|
|
*
|
|
|
|
|
* @param c the {@code char} value to be written.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @param c the {@code char} value to be written.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void writeChar(int c) throws IOException {
|
|
|
|
@ -122,8 +121,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* Writes a four-byte {@code int} to the underlying output stream
|
|
|
|
|
* in little endian order, low byte first, high byte last
|
|
|
|
|
*
|
|
|
|
|
* @param i the {@code int} to be written.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @param i the {@code int} to be written.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void writeInt(int i) throws IOException {
|
|
|
|
@ -140,8 +139,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* Writes an eight-byte {@code long} to the underlying output stream
|
|
|
|
|
* in little endian order, low byte first, high byte last
|
|
|
|
|
*
|
|
|
|
|
* @param l the {@code long} to be written.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @param l the {@code long} to be written.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void writeLong(long l) throws IOException {
|
|
|
|
@ -162,8 +161,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* Writes a 4 byte Java float to the underlying output stream in
|
|
|
|
|
* little endian order.
|
|
|
|
|
*
|
|
|
|
|
* @param f the {@code float} value to be written.
|
|
|
|
|
* @exception IOException if an I/O error occurs.
|
|
|
|
|
* @param f the {@code float} value to be written.
|
|
|
|
|
* @throws IOException if an I/O error occurs.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public final void writeFloat(float f) throws IOException {
|
|
|
|
@ -176,8 +175,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* Writes an 8 byte Java double to the underlying output stream in
|
|
|
|
|
* little endian order.
|
|
|
|
|
*
|
|
|
|
|
* @param d the {@code double} value to be written.
|
|
|
|
|
* @exception IOException if an I/O error occurs.
|
|
|
|
|
* @param d the {@code double} value to be written.
|
|
|
|
|
* @throws IOException if an I/O error occurs.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public final void writeDouble(double d) throws IOException {
|
|
|
|
@ -191,10 +190,10 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* bytes. Each character is written to the data output stream as
|
|
|
|
|
* if by the {@code writeByte()} method.
|
|
|
|
|
*
|
|
|
|
|
* @param s the {@code String} value to be written.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @see java.io.DataOutputStream#writeByte(int)
|
|
|
|
|
* @see java.io.DataOutputStream#out
|
|
|
|
|
* @param s the {@code String} value to be written.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @see java.io.DataOutputStream#writeByte(int)
|
|
|
|
|
* @see java.io.DataOutputStream#out
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void writeBytes(String s) throws IOException {
|
|
|
|
@ -211,10 +210,10 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* characters. Each character is written to the data output stream as
|
|
|
|
|
* if by the {@code writeChar} method.
|
|
|
|
|
*
|
|
|
|
|
* @param s a {@code String} value to be written.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @see java.io.DataOutputStream#writeChar(int)
|
|
|
|
|
* @see java.io.DataOutputStream#out
|
|
|
|
|
* @param s a {@code String} value to be written.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @see java.io.DataOutputStream#writeChar(int)
|
|
|
|
|
* @see java.io.DataOutputStream#out
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void writeChars(String s) throws IOException {
|
|
|
|
@ -239,10 +238,10 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* in the string. Next each character of the string is written
|
|
|
|
|
* using the UTF-8 encoding for the character.
|
|
|
|
|
*
|
|
|
|
|
* @param s the string to be written.
|
|
|
|
|
* @exception UTFDataFormatException if the string is longer than
|
|
|
|
|
* 65,535 characters.
|
|
|
|
|
* @exception IOException if the underlying stream throws an IOException.
|
|
|
|
|
* @param s the string to be written.
|
|
|
|
|
* @throws UTFDataFormatException if the string is longer than
|
|
|
|
|
* 65,535 characters.
|
|
|
|
|
* @throws IOException if the underlying stream throws an IOException.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void writeUTF(String s) throws IOException {
|
|
|
|
@ -250,7 +249,7 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
int numchars = s.length();
|
|
|
|
|
int numbytes = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0 ; i < numchars ; i++) {
|
|
|
|
|
for (int i = 0; i < numchars; i++) {
|
|
|
|
|
int c = s.charAt(i);
|
|
|
|
|
if ((c >= 0x0001) && (c <= 0x007F)) {
|
|
|
|
|
numbytes++;
|
|
|
|
@ -267,19 +266,17 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
|
|
|
|
|
out.write((numbytes >>> 8) & 0xFF);
|
|
|
|
|
out.write(numbytes & 0xFF);
|
|
|
|
|
for (int i = 0 ; i < numchars ; i++) {
|
|
|
|
|
for (int i = 0; i < numchars; i++) {
|
|
|
|
|
int c = s.charAt(i);
|
|
|
|
|
if ((c >= 0x0001) && (c <= 0x007F)) {
|
|
|
|
|
out.write(c);
|
|
|
|
|
}
|
|
|
|
|
else if (c > 0x07FF) {
|
|
|
|
|
} else if (c > 0x07FF) {
|
|
|
|
|
out.write(0xE0 | ((c >> 12) & 0x0F));
|
|
|
|
|
out.write(0x80 | ((c >> 6) & 0x3F));
|
|
|
|
|
out.write(0x80 | ((c >> 6) & 0x3F));
|
|
|
|
|
out.write(0x80 | (c & 0x3F));
|
|
|
|
|
written += 2;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
out.write(0xC0 | ((c >> 6) & 0x1F));
|
|
|
|
|
} else {
|
|
|
|
|
out.write(0xC0 | ((c >> 6) & 0x1F));
|
|
|
|
|
out.write(0x80 | (c & 0x3F));
|
|
|
|
|
written += 1;
|
|
|
|
|
}
|
|
|
|
@ -294,7 +291,8 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
|
|
|
|
|
* (This class is not thread-safe with respect to this method. It is
|
|
|
|
|
* possible that this number is temporarily less than the actual
|
|
|
|
|
* number of bytes written.)
|
|
|
|
|
* @return the value of the {@code written} field.
|
|
|
|
|
*
|
|
|
|
|
* @return the value of the {@code written} field.
|
|
|
|
|
*/
|
|
|
|
|
public int size() {
|
|
|
|
|
return this.written;
|
|
|
|
|