Code cleanup
This commit is contained in:
parent
a21c1f3cf4
commit
6037a906dc
@ -100,7 +100,7 @@ public class SafeDataOutputStream extends SafeFilterOutputStream implements Safe
|
|||||||
* @param len the number of bytes to write.
|
* @param len the number of bytes to write.
|
||||||
* @see SafeFilterOutputStream#out
|
* @see SafeFilterOutputStream#out
|
||||||
*/
|
*/
|
||||||
public void write(byte b[], int off, int len)
|
public void write(byte[] b, int off, int len)
|
||||||
{
|
{
|
||||||
out.write(b, off, len);
|
out.write(b, off, len);
|
||||||
incCount(len);
|
incCount(len);
|
||||||
@ -159,7 +159,7 @@ public class SafeDataOutputStream extends SafeFilterOutputStream implements Safe
|
|||||||
*/
|
*/
|
||||||
public final void writeShort(int v) {
|
public final void writeShort(int v) {
|
||||||
out.write((v >>> 8) & 0xFF);
|
out.write((v >>> 8) & 0xFF);
|
||||||
out.write((v >>> 0) & 0xFF);
|
out.write((v) & 0xFF);
|
||||||
incCount(2);
|
incCount(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ public class SafeDataOutputStream extends SafeFilterOutputStream implements Safe
|
|||||||
*/
|
*/
|
||||||
public final void writeChar(int v) {
|
public final void writeChar(int v) {
|
||||||
out.write((v >>> 8) & 0xFF);
|
out.write((v >>> 8) & 0xFF);
|
||||||
out.write((v >>> 0) & 0xFF);
|
out.write((v) & 0xFF);
|
||||||
incCount(2);
|
incCount(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,11 +189,11 @@ public class SafeDataOutputStream extends SafeFilterOutputStream implements Safe
|
|||||||
out.write((v >>> 24) & 0xFF);
|
out.write((v >>> 24) & 0xFF);
|
||||||
out.write((v >>> 16) & 0xFF);
|
out.write((v >>> 16) & 0xFF);
|
||||||
out.write((v >>> 8) & 0xFF);
|
out.write((v >>> 8) & 0xFF);
|
||||||
out.write((v >>> 0) & 0xFF);
|
out.write((v) & 0xFF);
|
||||||
incCount(4);
|
incCount(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte writeBuffer[] = new byte[8];
|
private final byte[] writeBuffer = new byte[8];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a {@code long} to the underlying output stream as eight
|
* Writes a {@code long} to the underlying output stream as eight
|
||||||
@ -211,7 +211,7 @@ public class SafeDataOutputStream extends SafeFilterOutputStream implements Safe
|
|||||||
writeBuffer[4] = (byte)(v >>> 24);
|
writeBuffer[4] = (byte)(v >>> 24);
|
||||||
writeBuffer[5] = (byte)(v >>> 16);
|
writeBuffer[5] = (byte)(v >>> 16);
|
||||||
writeBuffer[6] = (byte)(v >>> 8);
|
writeBuffer[6] = (byte)(v >>> 8);
|
||||||
writeBuffer[7] = (byte)(v >>> 0);
|
writeBuffer[7] = (byte)(v);
|
||||||
out.write(writeBuffer, 0, 8);
|
out.write(writeBuffer, 0, 8);
|
||||||
incCount(8);
|
incCount(8);
|
||||||
}
|
}
|
||||||
@ -282,7 +282,7 @@ public class SafeDataOutputStream extends SafeFilterOutputStream implements Safe
|
|||||||
for (int i = 0 ; i < len ; i++) {
|
for (int i = 0 ; i < len ; i++) {
|
||||||
int v = s.charAt(i);
|
int v = s.charAt(i);
|
||||||
out.write((v >>> 8) & 0xFF);
|
out.write((v >>> 8) & 0xFF);
|
||||||
out.write((v >>> 0) & 0xFF);
|
out.write((v) & 0xFF);
|
||||||
}
|
}
|
||||||
incCount(len * 2);
|
incCount(len * 2);
|
||||||
}
|
}
|
||||||
@ -359,8 +359,7 @@ public class SafeDataOutputStream extends SafeFilterOutputStream implements Safe
|
|||||||
|
|
||||||
static int writeUTF(int strlen, int utflen, String str, SafeDataOutput out) {
|
static int writeUTF(int strlen, int utflen, String str, SafeDataOutput out) {
|
||||||
final byte[] bytearr;
|
final byte[] bytearr;
|
||||||
if (out instanceof SafeDataOutputStream) {
|
if (out instanceof SafeDataOutputStream dos) {
|
||||||
SafeDataOutputStream dos = (SafeDataOutputStream)out;
|
|
||||||
if (dos.bytearr == null || (dos.bytearr.length < (utflen + 2)))
|
if (dos.bytearr == null || (dos.bytearr.length < (utflen + 2)))
|
||||||
dos.bytearr = new byte[(utflen*2) + 2];
|
dos.bytearr = new byte[(utflen*2) + 2];
|
||||||
bytearr = dos.bytearr;
|
bytearr = dos.bytearr;
|
||||||
@ -370,9 +369,9 @@ public class SafeDataOutputStream extends SafeFilterOutputStream implements Safe
|
|||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
|
bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
|
||||||
bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF);
|
bytearr[count++] = (byte) ((utflen) & 0xFF);
|
||||||
|
|
||||||
int i = 0;
|
int i;
|
||||||
for (i = 0; i < strlen; i++) { // optimized for initial run of ASCII
|
for (i = 0; i < strlen; i++) { // optimized for initial run of ASCII
|
||||||
int c = str.charAt(i);
|
int c = str.charAt(i);
|
||||||
if (c >= 0x80 || c == 0) break;
|
if (c >= 0x80 || c == 0) break;
|
||||||
@ -386,10 +385,10 @@ public class SafeDataOutputStream extends SafeFilterOutputStream implements Safe
|
|||||||
} else if (c >= 0x800) {
|
} else if (c >= 0x800) {
|
||||||
bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
|
bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
|
||||||
bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F));
|
bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F));
|
||||||
bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
|
bytearr[count++] = (byte) (0x80 | ((c) & 0x3F));
|
||||||
} else {
|
} else {
|
||||||
bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F));
|
bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F));
|
||||||
bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
|
bytearr[count++] = (byte) (0x80 | ((c) & 0x3F));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.write(bytearr, 0, utflen + 2);
|
out.write(bytearr, 0, utflen + 2);
|
||||||
|
Loading…
Reference in New Issue
Block a user