CharArrayWriter.java (14493:1aa088ea72cb) | CharArrayWriter.java (15375:143d43ae2446) |
---|---|
1/* 2 * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided --- 151 unchanged lines hidden (view full) --- 160 * <p> Depending on the specification of {@code toString} for the 161 * character sequence {@code csq}, the entire sequence may not be 162 * appended. For instance, invoking the {@code toString} method of a 163 * character buffer will return a subsequence whose content depends upon 164 * the buffer's position and limit. 165 * 166 * @param csq 167 * The character sequence to append. If {@code csq} is | 1/* 2 * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided --- 151 unchanged lines hidden (view full) --- 160 * <p> Depending on the specification of {@code toString} for the 161 * character sequence {@code csq}, the entire sequence may not be 162 * appended. For instance, invoking the {@code toString} method of a 163 * character buffer will return a subsequence whose content depends upon 164 * the buffer's position and limit. 165 * 166 * @param csq 167 * The character sequence to append. If {@code csq} is |
168 * {@code null}, then the four characters "{@code null}" are | 168 * {@code null}, then the four characters {@code "null"} are |
169 * appended to this writer. 170 * 171 * @return This writer 172 * 173 * @since 1.5 174 */ 175 public CharArrayWriter append(CharSequence csq) { | 169 * appended to this writer. 170 * 171 * @return This writer 172 * 173 * @since 1.5 174 */ 175 public CharArrayWriter append(CharSequence csq) { |
176 String s = (csq == null ? "null" : csq.toString()); | 176 String s = String.valueOf(csq); |
177 write(s, 0, s.length()); 178 return this; 179 } 180 181 /** 182 * Appends a subsequence of the specified character sequence to this writer. 183 * 184 * <p> An invocation of this method of the form 185 * {@code out.append(csq, start, end)} when 186 * {@code csq} is not {@code null}, behaves in 187 * exactly the same way as the invocation 188 * 189 * <pre> 190 * out.write(csq.subSequence(start, end).toString()) </pre> 191 * 192 * @param csq 193 * The character sequence from which a subsequence will be 194 * appended. If {@code csq} is {@code null}, then characters 195 * will be appended as if {@code csq} contained the four | 177 write(s, 0, s.length()); 178 return this; 179 } 180 181 /** 182 * Appends a subsequence of the specified character sequence to this writer. 183 * 184 * <p> An invocation of this method of the form 185 * {@code out.append(csq, start, end)} when 186 * {@code csq} is not {@code null}, behaves in 187 * exactly the same way as the invocation 188 * 189 * <pre> 190 * out.write(csq.subSequence(start, end).toString()) </pre> 191 * 192 * @param csq 193 * The character sequence from which a subsequence will be 194 * appended. If {@code csq} is {@code null}, then characters 195 * will be appended as if {@code csq} contained the four |
196 * characters "{@code null}". | 196 * characters {@code "null"}. |
197 * 198 * @param start 199 * The index of the first character in the subsequence 200 * 201 * @param end 202 * The index of the character following the last character in the 203 * subsequence 204 * 205 * @return This writer 206 * 207 * @throws IndexOutOfBoundsException 208 * If {@code start} or {@code end} are negative, {@code start} 209 * is greater than {@code end}, or {@code end} is greater than 210 * {@code csq.length()} 211 * 212 * @since 1.5 213 */ 214 public CharArrayWriter append(CharSequence csq, int start, int end) { | 197 * 198 * @param start 199 * The index of the first character in the subsequence 200 * 201 * @param end 202 * The index of the character following the last character in the 203 * subsequence 204 * 205 * @return This writer 206 * 207 * @throws IndexOutOfBoundsException 208 * If {@code start} or {@code end} are negative, {@code start} 209 * is greater than {@code end}, or {@code end} is greater than 210 * {@code csq.length()} 211 * 212 * @since 1.5 213 */ 214 public CharArrayWriter append(CharSequence csq, int start, int end) { |
215 String s = (csq == null ? "null" : csq).subSequence(start, end).toString(); 216 write(s, 0, s.length()); 217 return this; | 215 if (csq == null) csq = "null"; 216 return append(csq.subSequence(start, end)); |
218 } 219 220 /** 221 * Appends the specified character to this writer. 222 * 223 * <p> An invocation of this method of the form {@code out.append(c)} 224 * behaves in exactly the same way as the invocation 225 * --- 20 unchanged lines hidden (view full) --- 246 count = 0; 247 } 248 249 /** 250 * Returns a copy of the input data. 251 * 252 * @return an array of chars copied from the input data. 253 */ | 217 } 218 219 /** 220 * Appends the specified character to this writer. 221 * 222 * <p> An invocation of this method of the form {@code out.append(c)} 223 * behaves in exactly the same way as the invocation 224 * --- 20 unchanged lines hidden (view full) --- 245 count = 0; 246 } 247 248 /** 249 * Returns a copy of the input data. 250 * 251 * @return an array of chars copied from the input data. 252 */ |
254 public char toCharArray()[] { | 253 public char[] toCharArray() { |
255 synchronized (lock) { 256 return Arrays.copyOf(buf, count); 257 } 258 } 259 260 /** 261 * Returns the current size of the buffer. 262 * --- 29 unchanged lines hidden --- | 254 synchronized (lock) { 255 return Arrays.copyOf(buf, count); 256 } 257 } 258 259 /** 260 * Returns the current size of the buffer. 261 * --- 29 unchanged lines hidden --- |