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 * @author Ziver
* *
*/ */
public class BoundaryBufferedInputStream extends FilterInputStream{ public class BufferedBoundaryInputStream extends FilterInputStream{
/** The size of the buffer in Byte */ /** The size of the buffer in bytes */
public static final int DEFAULT_BUF_SIZE = 64*1024; public static final int DEFAULT_BUF_SIZE = 64*1024;
/** The raw buffer */ /** The raw buffer */
@ -55,7 +55,7 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
* *
* @param in is the InputStream that the buffer will use * @param in is the InputStream that the buffer will use
*/ */
public BoundaryBufferedInputStream(InputStream in){ public BufferedBoundaryInputStream(InputStream in){
this(in, DEFAULT_BUF_SIZE); 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 in is the InputStream that the buffer will use
* @param buf_size speifies the buffer size * @param buf_size speifies the buffer size
*/ */
public BoundaryBufferedInputStream(InputStream in, int buf_size){ public BufferedBoundaryInputStream(InputStream in, int buf_size){
super(in); super(in);
buf_end = 0; buf_end = 0;
buf_pos = 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 * A simple Class that mirrors a InputStream but
* also has an additional Closeable object that * also has an additional Closeable objects that
* will be closed with the InputStream * will be closed when the this object is closed.
* *
* @author Ziver * @author Ziver
*/ */
public class InputStreamCloser extends InputStream{ public class InputStreamCloser extends InputStream{
private Closeable c; private Closeable[] c;
private InputStream in; private InputStream in;
public InputStreamCloser(InputStream in, Closeable c){ public InputStreamCloser(InputStream in, Closeable... c){
this.c = c; this.c = c;
this.in = in; this.in = in;
} }
public void close() throws IOException { public void close() throws IOException {
in.close(); in.close();
c.close(); for (Closeable stream : c)
stream.close();
} }
// Mirror functions // Mirror functions

View file

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