001: /*
002: Copyright © 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
003:
004: Contributors:
005: * Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it):
006: contributed code is Copyright © 2006 by Stefano Chizzolini.
007:
008: This file should be part of the source code distribution of "PDF Clown library"
009: (the Program): see the accompanying README files for more info.
010:
011: This Program is free software; you can redistribute it and/or modify it under
012: the terms of the GNU General Public License as published by the Free Software
013: Foundation; either version 2 of the License, or (at your option) any later version.
014:
015: This Program is distributed in the hope that it will be useful, but WITHOUT ANY
016: WARRANTY, either expressed or implied; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
018:
019: You should have received a copy of the GNU General Public License along with this
020: Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
021:
022: Redistribution and use, with or without modification, are permitted provided that such
023: redistributions retain the above copyright notice, license and disclaimer, along with
024: this list of conditions.
025: */
026:
027: package it.stefanochizzolini.clown.bytes;
028:
029: import it.stefanochizzolini.clown.bytes.filters.Filter;
030:
031: /**
032: Buffer interface.
033: <p>Its pivotal concept is the array index.</p>
034: */
035: public interface IBuffer extends IInputStream {
036: /**
037: Appends a byte to the buffer.
038: @param data Byte to copy.
039: */
040: void append(byte data);
041:
042: /**
043: Appends a byte array to the buffer.
044: @param data Byte array to copy.
045: */
046: void append(byte[] data);
047:
048: /**
049: Appends a byte range to the buffer.
050: @param data Byte array from which the byte range has to be copied.
051: @param offset Location in the byte array at which copying begins.
052: @param length Number of bytes to copy.
053: */
054: void append(byte[] data, int offset, int length);
055:
056: /**
057: Appends a string to the buffer.
058: @param data String to copy.
059: */
060: void append(String data);
061:
062: /**
063: Appends an IInputStream to the buffer.
064: @param data Source data to copy.
065: */
066: void append(IInputStream data);
067:
068: /**
069: Gets a clone of the buffer.
070: @return Deep copy of the buffer.
071: */
072: IBuffer clone();
073:
074: /**
075: Applies the specified filter to decode the buffer.
076: @param filter Filter to use for decoding the buffer.
077: */
078: void decode(Filter filter);
079:
080: /**
081: Deletes a byte chunk from the buffer.
082: @param index Location at which deletion has to begin.
083: @param length Number of bytes to delete.
084: */
085: void delete(int index, int length);
086:
087: /**
088: Applies the specified filter to encode the buffer.
089: @param filter Filter to use for encoding the buffer.
090: @return Encoded buffer.
091: */
092: byte[] encode(Filter filter);
093:
094: /**
095: Gets the byte at a specified location.
096: @param index A location in the buffer.
097: @return Byte at the specified location.
098: */
099: int getByte(int index);
100:
101: /**
102: Gets the byte range beginning at a specified location.
103: @param index Location at which the byte range has to begin.
104: @param length Number of bytes to copy.
105: @return Byte range beginning at the specified location.
106: */
107: byte[] getByteArray(int index, int length);
108:
109: /**
110: Gets the string beginning at a specified location.
111: @param index Location at which the string has to begin.
112: @param length Number of bytes to convert.
113: @return String beginning at the specified location.
114: */
115: String getString(int index, int length);
116:
117: /**
118: Gets the allocated buffer size.
119: @return Allocated buffer size.
120: */
121: int getCapacity();
122:
123: /**
124: Inserts a byte array into the buffer.
125: @param index Location at which the byte array has to be inserted.
126: @param data Byte array to insert.
127: */
128: void insert(int index, byte[] data);
129:
130: /**
131: Inserts a byte range into the buffer.
132: @param index Location at which the byte range has to be inserted.
133: @param data Byte array from which the byte range has to be copied.
134: @param offset Location in the byte array at which copying begins.
135: @param length Number of bytes to copy.
136: */
137: void insert(int index, byte[] data, int offset, int length);
138:
139: /**
140: Inserts a string into the buffer.
141: @param index Location at which the string has to be inserted.
142: @param data String to insert.
143: */
144: void insert(int index, String data);
145:
146: /**
147: Inserts an IInputStream into the buffer.
148: @param index Location at which the IInputStream has to be inserted.
149: @param data Source data to copy.
150: */
151: void insert(int index, IInputStream data);
152:
153: /**
154: Replaces the buffer contents with a byte array.
155: @param index Location at which the byte array has to be copied.
156: @param data Byte array to copy.
157: */
158: void replace(int index, byte[] data);
159:
160: /**
161: Replaces the buffer contents with a byte range.
162: @param index Location at which the byte range has to be copied.
163: @param data Byte array from which the byte range has to be copied.
164: @param offset Location in the byte array at which copying begins.
165: @param length Number of bytes to copy.
166: */
167: void replace(int index, byte[] data, int offset, int length);
168:
169: /**
170: Replaces the buffer contents with a string.
171: @param index Location at which the string has to be copied.
172: @param data String to copy.
173: */
174: void replace(int index, String data);
175:
176: /**
177: Replaces the buffer contents with an IInputStream.
178: @param index Location at which the IInputStream has to be copied.
179: @param data Source data to copy.
180: */
181: void replace(int index, IInputStream data);
182:
183: /**
184: Sets the used buffer size.
185: @param value New length.
186: */
187: void setLength(int value);
188:
189: /**
190: Writes the buffer data to a stream.
191: @param stream Target stream.
192: */
193: void writeTo(IOutputStream stream);
194: }
|