jdk/src/share/classes/java/io/CharArrayWriter.java
author mchung
Thu, 12 Mar 2009 10:27:22 -0700
changeset 2277 445a331b4a8b
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6810254: Lazily instantiate the shared secret access objects Summary: Register the shutdown hooks only when needed and remove JavaIODeleteOnExitAccess Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1996-2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.io;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This class implements a character buffer that can be used as an Writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * The buffer automatically grows when data is written to the stream.  The data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * can be retrieved using toCharArray() and toString().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Note: Invoking close() on this class has no effect, and methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * of this class can be called after the stream has closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * without generating an IOException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author      Herb Jellinek
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class CharArrayWriter extends Writer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * The buffer where data is stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    protected char buf[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * The number of chars in the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Creates a new CharArrayWriter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public CharArrayWriter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Creates a new CharArrayWriter with the specified initial size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param initialSize  an int specifying the initial buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @exception IllegalArgumentException if initialSize is negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public CharArrayWriter(int initialSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (initialSize < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            throw new IllegalArgumentException("Negative initial size: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                               + initialSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        buf = new char[initialSize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Writes a character to the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public void write(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            int newcount = count + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (newcount > buf.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                buf = Arrays.copyOf(buf, Math.max(buf.length << 1, newcount));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            buf[count] = (char)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            count = newcount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Writes characters to the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param c the data to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param off       the start offset in the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param len       the number of chars that are written
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public void write(char c[], int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if ((off < 0) || (off > c.length) || (len < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            ((off + len) > c.length) || ((off + len) < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        } else if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            int newcount = count + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (newcount > buf.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                buf = Arrays.copyOf(buf, Math.max(buf.length << 1, newcount));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            System.arraycopy(c, off, buf, count, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            count = newcount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Write a portion of a string to the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param  str  String to be written from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param  off  Offset from which to start reading characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param  len  Number of characters to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public void write(String str, int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            int newcount = count + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (newcount > buf.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                buf = Arrays.copyOf(buf, Math.max(buf.length << 1, newcount));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            str.getChars(off, off + len, buf, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            count = newcount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Writes the contents of the buffer to another character stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param out       the output stream to write to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @throws IOException If an I/O error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void writeTo(Writer out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            out.write(buf, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Appends the specified character sequence to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <p> An invocation of this method of the form <tt>out.append(csq)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *     out.write(csq.toString()) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <p> Depending on the specification of <tt>toString</tt> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * character sequence <tt>csq</tt>, the entire sequence may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * appended. For instance, invoking the <tt>toString</tt> method of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * character buffer will return a subsequence whose content depends upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * the buffer's position and limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param  csq
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *         The character sequence to append.  If <tt>csq</tt> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *         <tt>null</tt>, then the four characters <tt>"null"</tt> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *         appended to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public CharArrayWriter append(CharSequence csq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        String s = (csq == null ? "null" : csq.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        write(s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Appends a subsequence of the specified character sequence to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <p> An invocation of this method of the form <tt>out.append(csq, start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *     out.write(csq.subSequence(start, end).toString()) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param  csq
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *         The character sequence from which a subsequence will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *         appended.  If <tt>csq</tt> is <tt>null</tt>, then characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *         will be appended as if <tt>csq</tt> contained the four
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *         characters <tt>"null"</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param  start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *         The index of the first character in the subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param  end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *         The index of the character following the last character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *         subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *          If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *          is greater than <tt>end</tt>, or <tt>end</tt> is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *          <tt>csq.length()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public CharArrayWriter append(CharSequence csq, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        String s = (csq == null ? "null" : csq).subSequence(start, end).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        write(s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Appends the specified character to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <p> An invocation of this method of the form <tt>out.append(c)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *     out.write(c) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param  c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *         The 16-bit character to append
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public CharArrayWriter append(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        write(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Resets the buffer so that you can use it again without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * throwing away the already allocated buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Returns a copy of the input data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @return an array of chars copied from the input data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public char toCharArray()[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            return Arrays.copyOf(buf, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Returns the current size of the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @return an int representing the current size of the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Converts input data to a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            return new String(buf, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Flush the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public void flush() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Close the stream.  This method does not release the buffer, since its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * contents might still be required. Note: Invoking this method in this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public void close() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
}