001: /*
002: * Copyright (c) xsocket.org, 2006 - 2008. All rights reserved.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
019: * The latest copy of this software may be found on http://www.xsocket.org/
020: */
021: package org.xsocket;
022:
023: import java.io.IOException;
024: import java.nio.BufferOverflowException;
025: import java.nio.ByteBuffer;
026: import java.nio.channels.GatheringByteChannel;
027: import java.nio.channels.ReadableByteChannel;
028: import java.nio.channels.WritableByteChannel;
029: import java.util.List;
030:
031: /**
032: * A data sink is an I/O resource capable of receiving data.
033: *
034: * @author grro@xsocket.org
035: */
036: public interface IDataSink {
037:
038: /**
039: * writes a byte to the data sink
040: *
041: * @param b the byte to write
042: * @return the number of written bytes
043: * @throws BufferOverflowException If the no enough space is available
044: * @throws IOException If some other I/O error occurs
045: */
046: public int write(byte b) throws IOException,
047: BufferOverflowException;
048:
049: /**
050: * writes bytes to the data sink
051: *
052: * @param bytes the bytes to write
053: * @return the number of written bytes
054: * @throws BufferOverflowException If the no enough space is available
055: * @throws IOException If some other I/O error occurs
056: */
057: public int write(byte... bytes) throws IOException,
058: BufferOverflowException;
059:
060: /**
061: * writes bytes to the data sink
062: *
063: * @param bytes the bytes to write
064: * @param offset The offset of the sub array to be used; must be non-negative and no larger than array.length. The new buffer`s position will be set to this value.
065: * @param length The length of the sub array to be used; must be non-negative and no larger than array.length - offset. The new buffer`s limit will be set to offset + length.
066: * @return the number of written bytes
067: * @throws BufferOverflowException If the no enough space is available
068: * @throws IOException If some other I/O error occurs
069: */
070: public int write(byte[] bytes, int offset, int length)
071: throws IOException, BufferOverflowException;
072:
073: /**
074: * {@link WritableByteChannel#write(ByteBuffer)}
075: */
076: public int write(ByteBuffer buffer) throws IOException,
077: BufferOverflowException;
078:
079: /**
080: * {@link GatheringByteChannel#write(ByteBuffer[])}
081: */
082: public long write(ByteBuffer[] buffers) throws IOException,
083: BufferOverflowException;
084:
085: /**
086: * see {@link GatheringByteChannel#write(ByteBuffer[], int, int)}
087: */
088: public long write(ByteBuffer[] srcs, int offset, int length)
089: throws IOException;
090:
091: /**
092: * writes a list of bytes to the data sink
093: *
094: * @param buffers the bytes to write
095: * @return the number of written bytes
096: * @throws BufferOverflowException If the no enough space is available
097: * @throws IOException If some other I/O error occurs
098: */
099: public long write(List<ByteBuffer> buffers) throws IOException,
100: BufferOverflowException;
101:
102: /**
103: * writes a int to the data sink
104: *
105: * @param i the int value to write
106: * @return the number of written bytes
107: * @throws BufferOverflowException If the no enough space is available
108: * @throws IOException If some other I/O error occurs
109: */
110: public int write(int i) throws IOException, BufferOverflowException;
111:
112: /**
113: * writes a short to the data sink
114: *
115: * @param s the short value to write
116: * @return the number of written bytes
117: * @throws BufferOverflowException If the no enough space is available
118: * @throws IOException If some other I/O error occurs
119: */
120: public int write(short s) throws IOException,
121: BufferOverflowException;
122:
123: /**
124: * writes a long to the data sink
125: *
126: * @param l the int value to write
127: * @return the number of written bytes
128: * @throws BufferOverflowException If the no enough space is available
129: * @throws IOException If some other I/O error occurs
130: */
131: public int write(long l) throws IOException,
132: BufferOverflowException;
133:
134: /**
135: * writes a double to the data sink
136: *
137: * @param d the int value to write
138: * @return the number of written bytes
139: * @throws BufferOverflowException If the no enough space is available
140: * @throws IOException If some other I/O error occurs
141: */
142: public int write(double d) throws IOException,
143: BufferOverflowException;
144:
145: /**
146: * writes a message
147: *
148: * @param message the message to write
149: * @return the number of written bytes
150: * @throws BufferOverflowException If the no enough space is available
151: * @throws IOException If some other I/O error occurs
152: */
153: public int write(String message) throws IOException,
154: BufferOverflowException;
155:
156: /**
157: * transfer the data of the source channel to this data sink
158: *
159: * @param source the source channel
160: * @return the number of transfered bytes
161: * @throws BufferOverflowException If the no enough space is available
162: * @throws IOException If some other I/O error occurs
163: */
164: public long transferFrom(ReadableByteChannel source)
165: throws IOException, BufferOverflowException;
166:
167: /**
168: * transfer the data of the source channel to this data sink
169: *
170: * @param source the source channel
171: * @param chunkSize the chunk size to use
172: * @return the number of transfered bytes
173: * @throws BufferOverflowException If the no enough space is available
174: * @throws IOException If some other I/O error occurs
175: */
176: public long transferFrom(ReadableByteChannel source, int chunkSize)
177: throws IOException, BufferOverflowException;
178: }
|