Writer.hx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. package java.io;
  2. /*
  3. * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * This code is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 only, as
  8. * published by the Free Software Foundation. Oracle designates this
  9. * particular file as subject to the "Classpath" exception as provided
  10. * by Oracle in the LICENSE file that accompanied this code.
  11. *
  12. * This code is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * version 2 for more details (a copy is included in the LICENSE file that
  16. * accompanied this code).
  17. *
  18. * You should have received a copy of the GNU General Public License version
  19. * 2 along with this work; if not, write to the Free Software Foundation,
  20. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23. * or visit www.oracle.com if you need additional information or have any
  24. * questions.
  25. */
  26. /**
  27. * Abstract class for writing to character streams. The only methods that a
  28. * subclass must implement are write(char[], int, int), flush(), and close().
  29. * Most subclasses, however, will override some of the methods defined here in
  30. * order to provide higher efficiency, additional functionality, or both.
  31. *
  32. * @see Writer
  33. * @see BufferedWriter
  34. * @see CharArrayWriter
  35. * @see FilterWriter
  36. * @see OutputStreamWriter
  37. * @see FileWriter
  38. * @see PipedWriter
  39. * @see PrintWriter
  40. * @see StringWriter
  41. * @see Reader
  42. *
  43. * @author Mark Reinhold
  44. * @since JDK1.1
  45. */
  46. @:require(java1) extern class Writer implements java.lang.Appendable implements java.io.Closeable implements java.io.Flushable
  47. {
  48. /**
  49. * The object used to synchronize operations on this stream. For
  50. * efficiency, a character-stream object may use an object other than
  51. * itself to protect critical sections. A subclass should therefore use
  52. * the object in this field rather than <tt>this</tt> or a synchronized
  53. * method.
  54. */
  55. private var lock : Dynamic;
  56. /**
  57. * Creates a new character-stream writer whose critical sections will
  58. * synchronize on the writer itself.
  59. */
  60. @:overload private function new() : Void;
  61. /**
  62. * Creates a new character-stream writer whose critical sections will
  63. * synchronize on the given object.
  64. *
  65. * @param lock
  66. * Object to synchronize on
  67. */
  68. @:overload private function new(lock : Dynamic) : Void;
  69. /**
  70. * Writes a single character. The character to be written is contained in
  71. * the 16 low-order bits of the given integer value; the 16 high-order bits
  72. * are ignored.
  73. *
  74. * <p> Subclasses that intend to support efficient single-character output
  75. * should override this method.
  76. *
  77. * @param c
  78. * int specifying a character to be written
  79. *
  80. * @throws IOException
  81. * If an I/O error occurs
  82. */
  83. @:overload public function write(c : Int) : Void;
  84. /**
  85. * Writes an array of characters.
  86. *
  87. * @param cbuf
  88. * Array of characters to be written
  89. *
  90. * @throws IOException
  91. * If an I/O error occurs
  92. */
  93. @:overload public function write(cbuf : java.NativeArray<java.StdTypes.Char16>) : Void;
  94. /**
  95. * Writes a portion of an array of characters.
  96. *
  97. * @param cbuf
  98. * Array of characters
  99. *
  100. * @param off
  101. * Offset from which to start writing characters
  102. *
  103. * @param len
  104. * Number of characters to write
  105. *
  106. * @throws IOException
  107. * If an I/O error occurs
  108. */
  109. @:overload @:abstract public function write(cbuf : java.NativeArray<java.StdTypes.Char16>, off : Int, len : Int) : Void;
  110. /**
  111. * Writes a string.
  112. *
  113. * @param str
  114. * String to be written
  115. *
  116. * @throws IOException
  117. * If an I/O error occurs
  118. */
  119. @:overload public function write(str : String) : Void;
  120. /**
  121. * Writes a portion of a string.
  122. *
  123. * @param str
  124. * A String
  125. *
  126. * @param off
  127. * Offset from which to start writing characters
  128. *
  129. * @param len
  130. * Number of characters to write
  131. *
  132. * @throws IndexOutOfBoundsException
  133. * If <tt>off</tt> is negative, or <tt>len</tt> is negative,
  134. * or <tt>off+len</tt> is negative or greater than the length
  135. * of the given string
  136. *
  137. * @throws IOException
  138. * If an I/O error occurs
  139. */
  140. @:overload public function write(str : String, off : Int, len : Int) : Void;
  141. /**
  142. * Appends the specified character sequence to this writer.
  143. *
  144. * <p> An invocation of this method of the form <tt>out.append(csq)</tt>
  145. * behaves in exactly the same way as the invocation
  146. *
  147. * <pre>
  148. * out.write(csq.toString()) </pre>
  149. *
  150. * <p> Depending on the specification of <tt>toString</tt> for the
  151. * character sequence <tt>csq</tt>, the entire sequence may not be
  152. * appended. For instance, invoking the <tt>toString</tt> method of a
  153. * character buffer will return a subsequence whose content depends upon
  154. * the buffer's position and limit.
  155. *
  156. * @param csq
  157. * The character sequence to append. If <tt>csq</tt> is
  158. * <tt>null</tt>, then the four characters <tt>"null"</tt> are
  159. * appended to this writer.
  160. *
  161. * @return This writer
  162. *
  163. * @throws IOException
  164. * If an I/O error occurs
  165. *
  166. * @since 1.5
  167. */
  168. @:require(java5) @:overload public function append(csq : java.lang.CharSequence) : Writer;
  169. /**
  170. * Appends a subsequence of the specified character sequence to this writer.
  171. * <tt>Appendable</tt>.
  172. *
  173. * <p> An invocation of this method of the form <tt>out.append(csq, start,
  174. * end)</tt> when <tt>csq</tt> is not <tt>null</tt> behaves in exactly the
  175. * same way as the invocation
  176. *
  177. * <pre>
  178. * out.write(csq.subSequence(start, end).toString()) </pre>
  179. *
  180. * @param csq
  181. * The character sequence from which a subsequence will be
  182. * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
  183. * will be appended as if <tt>csq</tt> contained the four
  184. * characters <tt>"null"</tt>.
  185. *
  186. * @param start
  187. * The index of the first character in the subsequence
  188. *
  189. * @param end
  190. * The index of the character following the last character in the
  191. * subsequence
  192. *
  193. * @return This writer
  194. *
  195. * @throws IndexOutOfBoundsException
  196. * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
  197. * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
  198. * <tt>csq.length()</tt>
  199. *
  200. * @throws IOException
  201. * If an I/O error occurs
  202. *
  203. * @since 1.5
  204. */
  205. @:require(java5) @:overload public function append(csq : java.lang.CharSequence, start : Int, end : Int) : Writer;
  206. /**
  207. * Appends the specified character to this writer.
  208. *
  209. * <p> An invocation of this method of the form <tt>out.append(c)</tt>
  210. * behaves in exactly the same way as the invocation
  211. *
  212. * <pre>
  213. * out.write(c) </pre>
  214. *
  215. * @param c
  216. * The 16-bit character to append
  217. *
  218. * @return This writer
  219. *
  220. * @throws IOException
  221. * If an I/O error occurs
  222. *
  223. * @since 1.5
  224. */
  225. @:require(java5) @:overload public function append(c : java.StdTypes.Char16) : Writer;
  226. /**
  227. * Flushes the stream. If the stream has saved any characters from the
  228. * various write() methods in a buffer, write them immediately to their
  229. * intended destination. Then, if that destination is another character or
  230. * byte stream, flush it. Thus one flush() invocation will flush all the
  231. * buffers in a chain of Writers and OutputStreams.
  232. *
  233. * <p> If the intended destination of this stream is an abstraction provided
  234. * by the underlying operating system, for example a file, then flushing the
  235. * stream guarantees only that bytes previously written to the stream are
  236. * passed to the operating system for writing; it does not guarantee that
  237. * they are actually written to a physical device such as a disk drive.
  238. *
  239. * @throws IOException
  240. * If an I/O error occurs
  241. */
  242. @:overload @:abstract public function flush() : Void;
  243. /**
  244. * Closes the stream, flushing it first. Once the stream has been closed,
  245. * further write() or flush() invocations will cause an IOException to be
  246. * thrown. Closing a previously closed stream has no effect.
  247. *
  248. * @throws IOException
  249. * If an I/O error occurs
  250. */
  251. @:overload @:abstract public function close() : Void;
  252. }