This commit is contained in:
Ziver Koc 2016-07-13 21:29:38 +02:00
parent 5606f57514
commit dc91d5e992
4 changed files with 44 additions and 28 deletions

View file

@ -117,11 +117,17 @@ public class BufferedBoundaryInputStreamTest {
}
@Test
public void readArr_multiCharBoundary() throws IOException {
BufferedBoundaryInputStream in = getBufferedBoundaryInputStream("aaa1234", "1234");
BufferedBoundaryInputStream in = getBufferedBoundaryInputStream(
"------------------------------83ff53821b7chello------------------------------83ff53821b7c--",
"------------------------------83ff53821b7c");
assertEquals('a', in.read());
assertEquals('a', in.read());
assertEquals('a', in.read());
assertEquals(-1, in.read());
assertTrue(in.hasNext()); in.next();
assertEquals("hello", IOUtil.readContentAsString(in));
assertEquals(-1, in.read());
assertTrue(in.hasNext()); in.next();
assertEquals('-', in.read());
assertEquals('-', in.read());
assertEquals(-1, in.read());
assertFalse(in.hasNext());
@ -194,12 +200,14 @@ public class BufferedBoundaryInputStreamTest {
@Test
public void read_largeData() throws IOException {
String data = "aaaaaaaaaaaa#aa#aaaaaaaaaaaaaaa#";
String data = "#aaaaaaaaaaaa#aa#aaaaaaaaaaaaaaa#";
StringInputStream inin = new StringInputStream(data);
BufferedBoundaryInputStream in = new BufferedBoundaryInputStream(inin, 10);
in.setBoundary("#");
assertEquals(-1, in.read());
assertTrue(in.hasNext());
in.next();
for (int i=0; i<12; ++i)
assertEquals('a', in.read());
assertEquals(-1, in.read());

View file

@ -1,8 +1,10 @@
package zutil.net.http.multipart;
import org.junit.Test;
import zutil.io.IOUtil;
import zutil.io.StringInputStream;
import java.io.IOException;
import java.util.Iterator;
import static junit.framework.TestCase.assertFalse;
@ -43,24 +45,25 @@ public class MultipartParserTest {
}
@Test
public void singleFileUpload() {
String input =
public void singleFileUpload() throws IOException {
String input_start =
"------------------------------83ff53821b7c\n" +
"Content-Disposition: form-data; name=\"img\"; filename=\"a.png\"\n" +
"Content-Type: application/octet-stream\n" +
"\n" +
"\n";
String input_data =
"?PNG\n" +
"\n" +
"IHD?wS??iCCPICC Profilex?T?kA?6n??Zk?x?\"IY?hE?6?bk\n" +
"Y?<ߡ)??????9Nyx?+=?Y\"|@5-?\u007FM?S?%?@?H8??qR>?\u05CB??inf???O?????b??N?????~N??>?!?\n" +
"??V?J?p?8?da?sZHO?Ln?}&???wVQ?y?g????E??0\n" +
" ??\n" +
" IDAc????????-IEND?B`?\n" +
"------------------------------83ff53821b7c--";
"lkuytrewacvbnmloiuytrewrtyuiol,mnbvdc xswertyuioplm cdsertyuioölkjgf\n" +
"kgkfdgfhgfhgkhgvytvjgxslkyöiyfödgjdjhföjhdlgdgjfhföjhföiyföudlögföudöfö\n" +
"ögdljgdjhöfjhfdfsgdfg ryrt dtrd ytfc uhöiugljfkdkhdjgd\n" +
" xx\n" +
" kuykutfytdh ytrd trutrd trxxx";
String input_end = "\n------------------------------83ff53821b7c--";
MultipartParser parser = new MultipartParser(
new StringInputStream(input),
new StringInputStream(input_start+input_data+input_end),
"----------------------------83ff53821b7c",
input.length());
0);
// Assertions
Iterator<MultipartField> it = parser.iterator();
@ -71,6 +74,7 @@ public class MultipartParserTest {
assertEquals("img", fileField.getName());
assertEquals("a.png", fileField.getFilename());
assertEquals("application/octet-stream", fileField.getContentType());
assertEquals(input_data, new String(fileField.getContent()));
//assertFalse(it.hasNext()); //TODO: does not work, how to solve this?
}