📄 fastbytearrayoutputstream.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: FastByteArrayOutputStream.java
package org.apache.struts2.util;
import java.io.*;
import java.util.Iterator;
import java.util.LinkedList;
public class FastByteArrayOutputStream extends OutputStream
{
private static final int DEFAULT_BLOCK_SIZE = 8192;
private LinkedList buffers;
private byte buffer[];
private boolean closed;
private int blockSize;
private int index;
private int size;
public FastByteArrayOutputStream()
{
this(8192);
}
public FastByteArrayOutputStream(int aSize)
{
blockSize = aSize;
buffer = new byte[blockSize];
}
public int getSize()
{
return size + index;
}
public void close()
{
closed = true;
}
public byte[] toByteArray()
{
byte data[] = new byte[getSize()];
int pos = 0;
if (buffers != null)
{
for (Iterator iter = buffers.iterator(); iter.hasNext();)
{
byte bytes[] = (byte[])(byte[])iter.next();
System.arraycopy(bytes, 0, data, pos, blockSize);
pos += blockSize;
}
}
System.arraycopy(buffer, 0, data, pos, index);
return data;
}
public String toString()
{
return new String(toByteArray());
}
public void write(int datum)
throws IOException
{
if (closed)
throw new IOException("Stream closed");
if (index == blockSize)
addBuffer();
buffer[index++] = (byte)datum;
}
public void write(byte data[], int offset, int length)
throws IOException
{
if (data == null)
throw new NullPointerException();
if (offset < 0 || offset + length > data.length || length < 0)
throw new IndexOutOfBoundsException();
if (closed)
throw new IOException("Stream closed");
if (index + length > blockSize)
{
do
{
if (index == blockSize)
addBuffer();
int copyLength = blockSize - index;
if (length < copyLength)
copyLength = length;
System.arraycopy(data, offset, buffer, index, copyLength);
offset += copyLength;
index += copyLength;
length -= copyLength;
} while (length > 0);
} else
{
System.arraycopy(data, offset, buffer, index, length);
index += length;
}
}
public void writeTo(OutputStream out)
throws IOException
{
if (buffers != null)
{
byte bytes[];
for (Iterator iter = buffers.iterator(); iter.hasNext(); out.write(bytes, 0, blockSize))
bytes = (byte[])(byte[])iter.next();
}
out.write(buffer, 0, index);
}
public void writeTo(RandomAccessFile out)
throws IOException
{
if (buffers != null)
{
byte bytes[];
for (Iterator iter = buffers.iterator(); iter.hasNext(); out.write(bytes, 0, blockSize))
bytes = (byte[])(byte[])iter.next();
}
out.write(buffer, 0, index);
}
public void writeTo(Writer out, String encoding)
throws IOException
{
if (buffers != null)
{
for (Iterator iter = buffers.iterator(); iter.hasNext();)
{
byte bytes[] = (byte[])(byte[])iter.next();
if (encoding != null)
out.write(new String(bytes, encoding));
else
out.write(new String(bytes));
}
}
if (encoding != null)
out.write(new String(buffer, 0, index, encoding));
else
out.write(new String(buffer, 0, index));
}
protected void addBuffer()
{
if (buffers == null)
buffers = new LinkedList();
buffers.addLast(buffer);
buffer = new byte[blockSize];
size += index;
index = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -