home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- import sun.io.CharToByteConverter;
- import sun.io.ConversionBufferFullException;
-
- public class OutputStreamWriter extends Writer {
- private CharToByteConverter ctb;
- private OutputStream out;
- private static final int defaultByteBufferSize = 8192;
- // $FF: renamed from: bb byte[]
- private byte[] field_0;
- private int nextByte;
- private int nBytes;
-
- public OutputStreamWriter(OutputStream var1, String var2) throws UnsupportedEncodingException {
- this(var1, CharToByteConverter.getConverter(var2));
- }
-
- public OutputStreamWriter(OutputStream var1) {
- this(var1, CharToByteConverter.getDefault());
- }
-
- private OutputStreamWriter(OutputStream var1, CharToByteConverter var2) {
- super(var1);
- this.nextByte = 0;
- this.nBytes = 0;
- if (var1 == null) {
- throw new NullPointerException("out is null");
- } else {
- this.out = var1;
- this.ctb = var2;
- this.field_0 = new byte[8192];
- this.nBytes = 8192;
- }
- }
-
- public String getEncoding() {
- Object var1 = super.lock;
- synchronized(var1) {
- if (this.ctb != null) {
- String var2 = this.ctb.getCharacterEncoding();
- return var2;
- } else {
- Object var3 = null;
- return (String)var3;
- }
- }
- }
-
- private void ensureOpen() throws IOException {
- if (this.out == null) {
- throw new IOException("Stream closed");
- }
- }
-
- public void write(int var1) throws IOException {
- char[] var2 = new char[]{(char)var1};
- this.write((char[])var2, 0, 1);
- }
-
- public void write(char[] var1, int var2, int var3) throws IOException {
- Object var4 = super.lock;
- synchronized(var4) {
- this.ensureOpen();
- if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
- if (var3 != 0) {
- int var5 = var2;
- int var6 = var2 + var3;
- boolean var7 = false;
-
- while(var5 < var6) {
- boolean var8 = false;
-
- try {
- this.nextByte += this.ctb.convertAny(var1, var5, var6, this.field_0, this.nextByte, this.nBytes);
- var5 = var6;
- } catch (ConversionBufferFullException var12) {
- int var10 = this.ctb.nextCharIndex();
- if (var10 == var5 && var7) {
- throw new CharConversionException("Output buffer too small");
- }
-
- var5 = var10;
- var8 = true;
- this.nextByte = this.ctb.nextByteIndex();
- }
-
- if (this.nextByte >= this.nBytes || var8) {
- this.out.write(this.field_0, 0, this.nextByte);
- this.nextByte = 0;
- var7 = true;
- }
- }
-
- }
- } else {
- throw new IndexOutOfBoundsException();
- }
- }
- }
-
- public void write(String var1, int var2, int var3) throws IOException {
- if (var3 < 0) {
- throw new IndexOutOfBoundsException();
- } else {
- char[] var4 = new char[var3];
- var1.getChars(var2, var2 + var3, var4, 0);
- this.write((char[])var4, 0, var3);
- }
- }
-
- void flushBuffer() throws IOException {
- Object var1 = super.lock;
- synchronized(var1) {
- this.ensureOpen();
-
- while(true) {
- try {
- this.nextByte += this.ctb.flushAny(this.field_0, this.nextByte, this.nBytes);
- } catch (ConversionBufferFullException var4) {
- this.nextByte = this.ctb.nextByteIndex();
- }
-
- if (this.nextByte == 0) {
- return;
- }
-
- if (this.nextByte > 0) {
- this.out.write(this.field_0, 0, this.nextByte);
- this.nextByte = 0;
- }
- }
- }
- }
-
- public void flush() throws IOException {
- Object var1 = super.lock;
- synchronized(var1) {
- this.flushBuffer();
- this.out.flush();
- }
- }
-
- public void close() throws IOException {
- Object var1 = super.lock;
- synchronized(var1) {
- if (this.out != null) {
- this.flush();
- this.out.close();
- this.out = null;
- this.field_0 = null;
- this.ctb = null;
- }
- }
- }
- }
-