home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- class ObjectOutputStream$BlockDataOutputStream extends OutputStream implements DataOutput {
- private static final int MAX_BLOCK_SIZE = 1024;
- private static final int MAX_HEADER_SIZE = 5;
- private static final int CHAR_BUF_SIZE = 256;
- private final byte[] buf = new byte[1024];
- private final byte[] hbuf = new byte[5];
- private final char[] cbuf = new char[256];
- private boolean blkmode = false;
- private int pos = 0;
- private final OutputStream out;
- private final DataOutputStream dout;
-
- ObjectOutputStream$BlockDataOutputStream(OutputStream var1) {
- this.out = var1;
- this.dout = new DataOutputStream(this);
- }
-
- boolean setBlockDataMode(boolean var1) throws IOException {
- if (this.blkmode == var1) {
- return this.blkmode;
- } else {
- this.drain();
- this.blkmode = var1;
- return !this.blkmode;
- }
- }
-
- boolean getBlockDataMode() {
- return this.blkmode;
- }
-
- public void write(int var1) throws IOException {
- if (this.pos >= 1024) {
- this.drain();
- }
-
- this.buf[this.pos++] = (byte)var1;
- }
-
- public void write(byte[] var1) throws IOException {
- this.write(var1, 0, var1.length, false);
- }
-
- public void write(byte[] var1, int var2, int var3) throws IOException {
- this.write(var1, var2, var3, false);
- }
-
- public void flush() throws IOException {
- this.drain();
- this.out.flush();
- }
-
- public void close() throws IOException {
- this.flush();
- this.out.close();
- }
-
- void write(byte[] var1, int var2, int var3, boolean var4) throws IOException {
- if (!var4 && !this.blkmode) {
- this.drain();
- this.out.write(var1, var2, var3);
- } else {
- while(var3 > 0) {
- if (this.pos >= 1024) {
- this.drain();
- }
-
- if (var3 >= 1024 && !var4 && this.pos == 0) {
- this.writeBlockHeader(1024);
- this.out.write(var1, var2, 1024);
- var2 += 1024;
- var3 -= 1024;
- } else {
- int var5 = Math.min(var3, 1024 - this.pos);
- System.arraycopy(var1, var2, this.buf, this.pos, var5);
- this.pos += var5;
- var2 += var5;
- var3 -= var5;
- }
- }
-
- }
- }
-
- void drain() throws IOException {
- if (this.pos != 0) {
- if (this.blkmode) {
- this.writeBlockHeader(this.pos);
- }
-
- this.out.write(this.buf, 0, this.pos);
- this.pos = 0;
- }
- }
-
- private void writeBlockHeader(int var1) throws IOException {
- if (var1 <= 255) {
- this.hbuf[0] = 119;
- this.hbuf[1] = (byte)var1;
- this.out.write(this.hbuf, 0, 2);
- } else {
- this.hbuf[0] = 122;
- Bits.putInt(this.hbuf, 1, var1);
- this.out.write(this.hbuf, 0, 5);
- }
-
- }
-
- public void writeBoolean(boolean var1) throws IOException {
- if (this.pos >= 1024) {
- this.drain();
- }
-
- Bits.putBoolean(this.buf, this.pos++, var1);
- }
-
- public void writeByte(int var1) throws IOException {
- if (this.pos >= 1024) {
- this.drain();
- }
-
- this.buf[this.pos++] = (byte)var1;
- }
-
- public void writeChar(int var1) throws IOException {
- if (this.pos + 2 <= 1024) {
- Bits.putChar(this.buf, this.pos, (char)var1);
- this.pos += 2;
- } else {
- this.dout.writeChar(var1);
- }
-
- }
-
- public void writeShort(int var1) throws IOException {
- if (this.pos + 2 <= 1024) {
- Bits.putShort(this.buf, this.pos, (short)var1);
- this.pos += 2;
- } else {
- this.dout.writeShort(var1);
- }
-
- }
-
- public void writeInt(int var1) throws IOException {
- if (this.pos + 4 <= 1024) {
- Bits.putInt(this.buf, this.pos, var1);
- this.pos += 4;
- } else {
- this.dout.writeInt(var1);
- }
-
- }
-
- public void writeFloat(float var1) throws IOException {
- if (this.pos + 4 <= 1024) {
- Bits.putFloat(this.buf, this.pos, var1);
- this.pos += 4;
- } else {
- this.dout.writeFloat(var1);
- }
-
- }
-
- public void writeLong(long var1) throws IOException {
- if (this.pos + 8 <= 1024) {
- Bits.putLong(this.buf, this.pos, var1);
- this.pos += 8;
- } else {
- this.dout.writeLong(var1);
- }
-
- }
-
- public void writeDouble(double var1) throws IOException {
- if (this.pos + 8 <= 1024) {
- Bits.putDouble(this.buf, this.pos, var1);
- this.pos += 8;
- } else {
- this.dout.writeDouble(var1);
- }
-
- }
-
- public void writeBytes(String var1) throws IOException {
- int var2 = var1.length();
- int var3 = 0;
- int var4 = 0;
-
- int var6;
- for(int var5 = 0; var5 < var2; var5 += var6) {
- if (var3 >= var4) {
- var3 = 0;
- var4 = Math.min(var2 - var5, 256);
- var1.getChars(var5, var5 + var4, this.cbuf, 0);
- }
-
- if (this.pos >= 1024) {
- this.drain();
- }
-
- var6 = Math.min(var4 - var3, 1024 - this.pos);
-
- for(int var7 = this.pos + var6; this.pos < var7; this.buf[this.pos++] = (byte)this.cbuf[var3++]) {
- }
- }
-
- }
-
- public void writeChars(String var1) throws IOException {
- int var2 = var1.length();
-
- int var4;
- for(int var3 = 0; var3 < var2; var3 += var4) {
- var4 = Math.min(var2 - var3, 256);
- var1.getChars(var3, var3 + var4, this.cbuf, 0);
- this.writeChars(this.cbuf, 0, var4);
- }
-
- }
-
- public void writeUTF(String var1) throws IOException {
- this.writeUTF(var1, this.getUTFLength(var1));
- }
-
- void writeBooleans(boolean[] var1, int var2, int var3) throws IOException {
- int var4 = var2 + var3;
-
- while(var2 < var4) {
- if (this.pos >= 1024) {
- this.drain();
- }
-
- int var5 = Math.min(var4, var2 + (1024 - this.pos));
-
- while(var2 < var5) {
- Bits.putBoolean(this.buf, this.pos++, var1[var2++]);
- }
- }
-
- }
-
- void writeChars(char[] var1, int var2, int var3) throws IOException {
- short var4 = 1022;
- int var5 = var2 + var3;
-
- while(var2 < var5) {
- if (this.pos <= var4) {
- int var6 = 1024 - this.pos >> 1;
-
- for(int var7 = Math.min(var5, var2 + var6); var2 < var7; this.pos += 2) {
- Bits.putChar(this.buf, this.pos, var1[var2++]);
- }
- } else {
- this.dout.writeChar(var1[var2++]);
- }
- }
-
- }
-
- void writeShorts(short[] var1, int var2, int var3) throws IOException {
- short var4 = 1022;
- int var5 = var2 + var3;
-
- while(var2 < var5) {
- if (this.pos <= var4) {
- int var6 = 1024 - this.pos >> 1;
-
- for(int var7 = Math.min(var5, var2 + var6); var2 < var7; this.pos += 2) {
- Bits.putShort(this.buf, this.pos, var1[var2++]);
- }
- } else {
- this.dout.writeShort(var1[var2++]);
- }
- }
-
- }
-
- void writeInts(int[] var1, int var2, int var3) throws IOException {
- short var4 = 1020;
- int var5 = var2 + var3;
-
- while(var2 < var5) {
- if (this.pos <= var4) {
- int var6 = 1024 - this.pos >> 2;
-
- for(int var7 = Math.min(var5, var2 + var6); var2 < var7; this.pos += 4) {
- Bits.putInt(this.buf, this.pos, var1[var2++]);
- }
- } else {
- this.dout.writeInt(var1[var2++]);
- }
- }
-
- }
-
- void writeFloats(float[] var1, int var2, int var3) throws IOException {
- short var4 = 1020;
- int var5 = var2 + var3;
-
- while(var2 < var5) {
- if (this.pos <= var4) {
- int var6 = 1024 - this.pos >> 2;
- int var7 = Math.min(var5 - var2, var6);
- ObjectOutputStream.access$400(var1, var2, this.buf, this.pos, var7);
- var2 += var7;
- this.pos += var7 << 2;
- } else {
- this.dout.writeFloat(var1[var2++]);
- }
- }
-
- }
-
- void writeLongs(long[] var1, int var2, int var3) throws IOException {
- short var4 = 1016;
- int var5 = var2 + var3;
-
- while(var2 < var5) {
- if (this.pos <= var4) {
- int var6 = 1024 - this.pos >> 3;
-
- for(int var7 = Math.min(var5, var2 + var6); var2 < var7; this.pos += 8) {
- Bits.putLong(this.buf, this.pos, var1[var2++]);
- }
- } else {
- this.dout.writeLong(var1[var2++]);
- }
- }
-
- }
-
- void writeDoubles(double[] var1, int var2, int var3) throws IOException {
- short var4 = 1016;
- int var5 = var2 + var3;
-
- while(var2 < var5) {
- if (this.pos <= var4) {
- int var6 = 1024 - this.pos >> 3;
- int var7 = Math.min(var5 - var2, var6);
- ObjectOutputStream.access$500(var1, var2, this.buf, this.pos, var7);
- var2 += var7;
- this.pos += var7 << 3;
- } else {
- this.dout.writeDouble(var1[var2++]);
- }
- }
-
- }
-
- long getUTFLength(String var1) {
- int var2 = var1.length();
- long var3 = 0L;
-
- int var6;
- for(int var5 = 0; var5 < var2; var5 += var6) {
- var6 = Math.min(var2 - var5, 256);
- var1.getChars(var5, var5 + var6, this.cbuf, 0);
-
- for(int var7 = 0; var7 < var6; ++var7) {
- char var8 = this.cbuf[var7];
- if (var8 >= 1 && var8 <= 127) {
- ++var3;
- } else if (var8 > 2047) {
- var3 += 3L;
- } else {
- var3 += 2L;
- }
- }
- }
-
- return var3;
- }
-
- void writeUTF(String var1, long var2) throws IOException {
- if (var2 > 65535L) {
- throw new UTFDataFormatException();
- } else {
- this.writeShort((int)var2);
- if (var2 == (long)var1.length()) {
- this.writeBytes(var1);
- } else {
- this.writeUTFBody(var1);
- }
-
- }
- }
-
- void writeLongUTF(String var1) throws IOException {
- this.writeLongUTF(var1, this.getUTFLength(var1));
- }
-
- void writeLongUTF(String var1, long var2) throws IOException {
- this.writeLong(var2);
- if (var2 == (long)var1.length()) {
- this.writeBytes(var1);
- } else {
- this.writeUTFBody(var1);
- }
-
- }
-
- private void writeUTFBody(String var1) throws IOException {
- short var2 = 1021;
- int var3 = var1.length();
-
- int var5;
- for(int var4 = 0; var4 < var3; var4 += var5) {
- var5 = Math.min(var3 - var4, 256);
- var1.getChars(var4, var4 + var5, this.cbuf, 0);
-
- for(int var6 = 0; var6 < var5; ++var6) {
- char var7 = this.cbuf[var6];
- if (this.pos <= var2) {
- if (var7 <= 127 && var7 != 0) {
- this.buf[this.pos++] = (byte)var7;
- } else if (var7 > 2047) {
- this.buf[this.pos + 2] = (byte)(128 | var7 >> 0 & 63);
- this.buf[this.pos + 1] = (byte)(128 | var7 >> 6 & 63);
- this.buf[this.pos + 0] = (byte)(224 | var7 >> 12 & 15);
- this.pos += 3;
- } else {
- this.buf[this.pos + 1] = (byte)(128 | var7 >> 0 & 63);
- this.buf[this.pos + 0] = (byte)(192 | var7 >> 6 & 31);
- this.pos += 2;
- }
- } else if (var7 <= 127 && var7 != 0) {
- this.write(var7);
- } else if (var7 > 2047) {
- this.write(224 | var7 >> 12 & 15);
- this.write(128 | var7 >> 6 & 63);
- this.write(128 | var7 >> 0 & 63);
- } else {
- this.write(192 | var7 >> 6 & 31);
- this.write(128 | var7 >> 0 & 63);
- }
- }
- }
-
- }
- }
-