1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/rt/emul/compact/src/main/java/java/io/OutputStream.java Tue Feb 26 16:54:16 2013 +0100
1.3 @@ -0,0 +1,154 @@
1.4 +/*
1.5 + * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +
1.29 +package java.io;
1.30 +
1.31 +/**
1.32 + * This abstract class is the superclass of all classes representing
1.33 + * an output stream of bytes. An output stream accepts output bytes
1.34 + * and sends them to some sink.
1.35 + * <p>
1.36 + * Applications that need to define a subclass of
1.37 + * <code>OutputStream</code> must always provide at least a method
1.38 + * that writes one byte of output.
1.39 + *
1.40 + * @author Arthur van Hoff
1.41 + * @see java.io.BufferedOutputStream
1.42 + * @see java.io.ByteArrayOutputStream
1.43 + * @see java.io.DataOutputStream
1.44 + * @see java.io.FilterOutputStream
1.45 + * @see java.io.InputStream
1.46 + * @see java.io.OutputStream#write(int)
1.47 + * @since JDK1.0
1.48 + */
1.49 +public abstract class OutputStream implements Closeable, Flushable {
1.50 + /**
1.51 + * Writes the specified byte to this output stream. The general
1.52 + * contract for <code>write</code> is that one byte is written
1.53 + * to the output stream. The byte to be written is the eight
1.54 + * low-order bits of the argument <code>b</code>. The 24
1.55 + * high-order bits of <code>b</code> are ignored.
1.56 + * <p>
1.57 + * Subclasses of <code>OutputStream</code> must provide an
1.58 + * implementation for this method.
1.59 + *
1.60 + * @param b the <code>byte</code>.
1.61 + * @exception IOException if an I/O error occurs. In particular,
1.62 + * an <code>IOException</code> may be thrown if the
1.63 + * output stream has been closed.
1.64 + */
1.65 + public abstract void write(int b) throws IOException;
1.66 +
1.67 + /**
1.68 + * Writes <code>b.length</code> bytes from the specified byte array
1.69 + * to this output stream. The general contract for <code>write(b)</code>
1.70 + * is that it should have exactly the same effect as the call
1.71 + * <code>write(b, 0, b.length)</code>.
1.72 + *
1.73 + * @param b the data.
1.74 + * @exception IOException if an I/O error occurs.
1.75 + * @see java.io.OutputStream#write(byte[], int, int)
1.76 + */
1.77 + public void write(byte b[]) throws IOException {
1.78 + write(b, 0, b.length);
1.79 + }
1.80 +
1.81 + /**
1.82 + * Writes <code>len</code> bytes from the specified byte array
1.83 + * starting at offset <code>off</code> to this output stream.
1.84 + * The general contract for <code>write(b, off, len)</code> is that
1.85 + * some of the bytes in the array <code>b</code> are written to the
1.86 + * output stream in order; element <code>b[off]</code> is the first
1.87 + * byte written and <code>b[off+len-1]</code> is the last byte written
1.88 + * by this operation.
1.89 + * <p>
1.90 + * The <code>write</code> method of <code>OutputStream</code> calls
1.91 + * the write method of one argument on each of the bytes to be
1.92 + * written out. Subclasses are encouraged to override this method and
1.93 + * provide a more efficient implementation.
1.94 + * <p>
1.95 + * If <code>b</code> is <code>null</code>, a
1.96 + * <code>NullPointerException</code> is thrown.
1.97 + * <p>
1.98 + * If <code>off</code> is negative, or <code>len</code> is negative, or
1.99 + * <code>off+len</code> is greater than the length of the array
1.100 + * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
1.101 + *
1.102 + * @param b the data.
1.103 + * @param off the start offset in the data.
1.104 + * @param len the number of bytes to write.
1.105 + * @exception IOException if an I/O error occurs. In particular,
1.106 + * an <code>IOException</code> is thrown if the output
1.107 + * stream is closed.
1.108 + */
1.109 + public void write(byte b[], int off, int len) throws IOException {
1.110 + if (b == null) {
1.111 + throw new NullPointerException();
1.112 + } else if ((off < 0) || (off > b.length) || (len < 0) ||
1.113 + ((off + len) > b.length) || ((off + len) < 0)) {
1.114 + throw new IndexOutOfBoundsException();
1.115 + } else if (len == 0) {
1.116 + return;
1.117 + }
1.118 + for (int i = 0 ; i < len ; i++) {
1.119 + write(b[off + i]);
1.120 + }
1.121 + }
1.122 +
1.123 + /**
1.124 + * Flushes this output stream and forces any buffered output bytes
1.125 + * to be written out. The general contract of <code>flush</code> is
1.126 + * that calling it is an indication that, if any bytes previously
1.127 + * written have been buffered by the implementation of the output
1.128 + * stream, such bytes should immediately be written to their
1.129 + * intended destination.
1.130 + * <p>
1.131 + * If the intended destination of this stream is an abstraction provided by
1.132 + * the underlying operating system, for example a file, then flushing the
1.133 + * stream guarantees only that bytes previously written to the stream are
1.134 + * passed to the operating system for writing; it does not guarantee that
1.135 + * they are actually written to a physical device such as a disk drive.
1.136 + * <p>
1.137 + * The <code>flush</code> method of <code>OutputStream</code> does nothing.
1.138 + *
1.139 + * @exception IOException if an I/O error occurs.
1.140 + */
1.141 + public void flush() throws IOException {
1.142 + }
1.143 +
1.144 + /**
1.145 + * Closes this output stream and releases any system resources
1.146 + * associated with this stream. The general contract of <code>close</code>
1.147 + * is that it closes the output stream. A closed stream cannot perform
1.148 + * output operations and cannot be reopened.
1.149 + * <p>
1.150 + * The <code>close</code> method of <code>OutputStream</code> does nothing.
1.151 + *
1.152 + * @exception IOException if an I/O error occurs.
1.153 + */
1.154 + public void close() throws IOException {
1.155 + }
1.156 +
1.157 +}