Renamed Boundary buffer and improved InputStreamCloser

This commit is contained in:
Ziver Koc 2016-07-06 17:35:58 +02:00
parent f77a757b6d
commit 765063ae47
3 changed files with 255 additions and 257 deletions

View file

@ -34,8 +34,8 @@ import java.io.InputStream;
* @author Ziver
*
*/
public class BoundaryBufferedInputStream extends FilterInputStream{
/** The size of the buffer in Byte */
public class BufferedBoundaryInputStream extends FilterInputStream{
/** The size of the buffer in bytes */
public static final int DEFAULT_BUF_SIZE = 64*1024;
/** The raw buffer */
@ -55,7 +55,7 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
*
* @param in is the InputStream that the buffer will use
*/
public BoundaryBufferedInputStream(InputStream in){
public BufferedBoundaryInputStream(InputStream in){
this(in, DEFAULT_BUF_SIZE);
}
@ -65,7 +65,7 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
* @param in is the InputStream that the buffer will use
* @param buf_size speifies the buffer size
*/
public BoundaryBufferedInputStream(InputStream in, int buf_size){
public BufferedBoundaryInputStream(InputStream in, int buf_size){
super(in);
buf_end = 0;
buf_pos = 0;

11
src/zutil/io/InputStreamCloser.java Normal file → Executable file
View file

@ -30,23 +30,24 @@ import java.io.InputStream;
/**
* A simple Class that mirrors a InputStream but
* also has an additional Closeable object that
* will be closed with the InputStream
* also has an additional Closeable objects that
* will be closed when the this object is closed.
*
* @author Ziver
*/
public class InputStreamCloser extends InputStream{
private Closeable c;
private Closeable[] c;
private InputStream in;
public InputStreamCloser(InputStream in, Closeable c){
public InputStreamCloser(InputStream in, Closeable... c){
this.c = c;
this.in = in;
}
public void close() throws IOException {
in.close();
c.close();
for (Closeable stream : c)
stream.close();
}
// Mirror functions

View file

@ -32,13 +32,12 @@ import static org.junit.Assert.assertEquals;
@SuppressWarnings("resource")
public class BoundaryBufferedInputStreamTest {
public class BufferedBoundaryInputStreamTest {
@Test
public void testReadB1() throws IOException {
StringInputStream inin = new StringInputStream();
BoundaryBufferedInputStream in = new BoundaryBufferedInputStream(inin);
inin.add("aaa#aaaaaaaaaaaaaaaa#aaaaaaaaaaaaaaa#");
StringInputStream inin = new StringInputStream("aaa#aaaaaaaaaaaaaaaa#aaaaaaaaaaaaaaa#");
BufferedBoundaryInputStream in = new BufferedBoundaryInputStream(inin);
in.setBoundary("#");
@ -63,9 +62,8 @@ public class BoundaryBufferedInputStreamTest {
@Test
public void testOnlyBoundaries() throws IOException {
StringInputStream inin = new StringInputStream();
BoundaryBufferedInputStream in = new BoundaryBufferedInputStream(inin);
inin.add("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
StringInputStream inin = new StringInputStream("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
BufferedBoundaryInputStream in = new BufferedBoundaryInputStream(inin);
in.setBoundary("a");
@ -83,9 +81,8 @@ public class BoundaryBufferedInputStreamTest {
@Test
public void testNoBounds() throws IOException {
String data = "1234567891011121314151617181920";
StringInputStream inin = new StringInputStream();
BoundaryBufferedInputStream in = new BoundaryBufferedInputStream(inin);
inin.add(data);
StringInputStream inin = new StringInputStream(data);
BufferedBoundaryInputStream in = new BufferedBoundaryInputStream(inin);
in.setBoundary("#");
int out;