001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.io;
019:
020: import org.apache.harmony.luni.util.Msg;
021:
022: /**
023: * OutputStream is an abstract class for all byte output streams. It provides
024: * basic method implementations for writing bytes to a stream.
025: *
026: * @see InputStream
027: */
028: public abstract class OutputStream implements Closeable, Flushable {
029:
030: /**
031: * Default constructor.
032: */
033: public OutputStream() {
034: super ();
035: }
036:
037: /**
038: * Close this OutputStream. Concrete implementations of this class should
039: * free any resources during close. This implementation does nothing.
040: *
041: * @throws IOException
042: * If an error occurs attempting to close this OutputStream.
043: */
044: public void close() throws IOException {
045: /* empty */
046: }
047:
048: /**
049: * Flush this OutputStream. Concrete implementations of this class should
050: * ensure any pending writes to the underlying stream are written out when
051: * this method is envoked. This implementation does nothing.
052: *
053: * @throws IOException
054: * If an error occurs attempting to flush this OutputStream.
055: */
056: public void flush() throws IOException {
057: /* empty */
058: }
059:
060: /**
061: * Writes the entire contents of the byte array <code>buffer</code> to
062: * this OutputStream.
063: *
064: * @param buffer
065: * the buffer to be written
066: *
067: * @throws IOException
068: * If an error occurs attempting to write to this OutputStream.
069: */
070: public void write(byte buffer[]) throws IOException {
071: write(buffer, 0, buffer.length);
072: }
073:
074: /**
075: * Writes <code>count</code> <code>bytes</code> from the byte array
076: * <code>buffer</code> starting at <code>offset</code> to this
077: * OutputStream.
078: *
079: * @param buffer
080: * the buffer to be written
081: * @param offset
082: * offset in buffer to get bytes
083: * @param count
084: * number of bytes in buffer to write
085: *
086: * @throws IOException
087: * If an error occurs attempting to write to this OutputStream.
088: * @throws IndexOutOfBoundsException
089: * If offset or count are outside of bounds.
090: */
091: public void write(byte buffer[], int offset, int count)
092: throws IOException {
093: // avoid int overflow, check null buffer
094: if (offset > buffer.length || offset < 0 || count < 0
095: || count > buffer.length - offset) {
096: throw new IndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
097: }
098: for (int i = offset; i < offset + count; i++) {
099: write(buffer[i]);
100: }
101: }
102:
103: /**
104: * Writes the specified byte <code>oneByte</code> to this OutputStream.
105: * Only the low order byte of <code>oneByte</code> is written.
106: *
107: * @param oneByte
108: * the byte to be written
109: *
110: * @throws IOException
111: * If an error occurs attempting to write to this OutputStream.
112: */
113: public abstract void write(int oneByte) throws IOException;
114: }
|