Package org.simpleframework.http.core

Examples of org.simpleframework.http.core.StreamCursor


   "--AaB03x--\r\n";
  
   public void testSimple() throws Exception {
      PartData list = new PartData();
      PartSeriesConsumer consumer = new PartSeriesConsumer(new ArrayAllocator(), list, "AaB03x".getBytes("UTF-8"));
      Cursor cursor = new StreamCursor(SIMPLE);
     
      while(!consumer.isFinished()) {
         consumer.consume(cursor);
      }  
      assertEquals(list.getParts().size(), 1);
      assertEquals(list.getParts().get(0).getContentType().getPrimary(), "text");
      assertEquals(list.getParts().get(0).getContentType().getSecondary(), "plain");
      assertEquals(list.getParts().get(0).getHeader("Content-Disposition"), "form-data; name='pics'; filename='file1.txt'");
      assertEquals(list.getParts().get(0).getContent(), "example contents of file1.txt ...");
      assertEquals(cursor.ready(), -1);    
      assertEquals(consumer.getBody().getContent(), SIMPLE);
   }
View Full Code Here


   }
  
   public void testNormal() throws Exception {
      PartData list = new PartData();
      PartSeriesConsumer consumer = new PartSeriesConsumer(new ArrayAllocator(), list, "AaB03x".getBytes("UTF-8"));
      Cursor cursor = new StreamCursor(NORMAL);
     
      while(!consumer.isFinished()) {
         consumer.consume(cursor);
      }  
      assertEquals(list.getParts().size(), 3);
      assertEquals(list.getParts().get(0).getContentType().getPrimary(), "text");
      assertEquals(list.getParts().get(0).getContentType().getSecondary(), "plain");
      assertEquals(list.getParts().get(0).getHeader("Content-Disposition"), "form-data; name='pics'; filename='file1.txt'");
      assertEquals(list.getParts().get(0).getContent(), "example contents of file1.txt");
      assertEquals(list.getParts().get(1).getContentType().getPrimary(), "text");
      assertEquals(list.getParts().get(1).getContentType().getSecondary(), "plain");
      assertEquals(list.getParts().get(1).getHeader("Content-Disposition"), "form-data; name='pics'; filename='file2.txt'");
      assertEquals(list.getParts().get(1).getContent(), "example contents of file2.txt");
      assertEquals(list.getParts().get(2).getContentType().getPrimary(), "text");
      assertEquals(list.getParts().get(2).getContentType().getSecondary(), "plain");
      assertEquals(list.getParts().get(2).getHeader("Content-Disposition"), "form-data; name='pics'; filename='file3.txt'");
      assertEquals(list.getParts().get(2).getContent(), "example contents of file3.txt ...");
      assertEquals(cursor.ready(), -1);    
      assertEquals(consumer.getBody().getContent(), NORMAL);
   }
View Full Code Here

   }
  
   public void testMixed() throws Exception {
      PartData list = new PartData();
      PartSeriesConsumer consumer = new PartSeriesConsumer(new ArrayAllocator(), list, "AaB03x".getBytes("UTF-8"));
      Cursor cursor = new StreamCursor(MIXED);
     
      while(!consumer.isFinished()) {
         consumer.consume(cursor);
      }  
      assertEquals(list.getParts().size(), 4);
      assertEquals(list.getParts().get(0).getContentType().getPrimary(), "text");
      assertEquals(list.getParts().get(0).getContentType().getSecondary(), "plain");
      assertEquals(list.getParts().get(0).getHeader("Content-Disposition"), "form-data; name='pics'; filename='file1.txt'");
      assertEquals(list.getParts().get(0).getContent(), "example contents of file1.txt");
      assertEquals(list.getParts().get(1).getContentType().getPrimary(), "text");
      assertEquals(list.getParts().get(1).getContentType().getSecondary(), "plain");
      assertEquals(list.getParts().get(1).getHeader("Content-Disposition"), "form-data; name='pics'; filename='file2.txt'");
      assertEquals(list.getParts().get(1).getContent(), "example contents of file2.txt ...");
      assertEquals(list.getParts().get(2).getContentType().getPrimary(), "text");
      assertEquals(list.getParts().get(2).getContentType().getSecondary(), "plain");
      assertEquals(list.getParts().get(2).getHeader("Content-Disposition"), "form-data; name='pics'; filename='file3.txt'");
      assertEquals(list.getParts().get(2).getContent(), "example contents of file3.txt ...");
      assertEquals(list.getParts().get(3).getContentType().getPrimary(), "text");
      assertEquals(list.getParts().get(3).getContentType().getSecondary(), "plain");
      assertEquals(list.getParts().get(3).getHeader("Content-Disposition"), "form-data; name='pics'; filename='file4.txt'");
      assertEquals(list.getParts().get(3).getContent(), "example contents of file4.txt ...");
      assertEquals(cursor.ready(), -1);          
      assertEquals(consumer.getBody().getContent(), MIXED);
   }
View Full Code Here

   }
  
   public void testDribble() throws Exception {
      PartData list = new PartData();
      PartSeriesConsumer consumer = new PartSeriesConsumer(new ArrayAllocator(), list, "AaB03x".getBytes("UTF-8"));
      Cursor cursor = new DribbleCursor(new StreamCursor(NORMAL), 1);
     
      while(!consumer.isFinished()) {
         consumer.consume(cursor);
      }  
      assertEquals(list.getParts().size(), 3);
View Full Code Here

      encode.close();
      byte[] data = out.toByteArray();
      byte[] plainText = plain.toByteArray();
      //System.out.println(">>"+new String(data, 0, data.length, "UTF-8")+"<<");
      //System.out.println("}}"+new String(plainText, 0, plainText.length,"UTF-8")+"{{");
      DribbleCursor cursor = new DribbleCursor(new StreamCursor(new ByteArrayInputStream(data)), dribble);
      ChunkedConsumer test = new ChunkedConsumer(this);
     
      while(!test.isFinished()) {
         test.consume(cursor);
      }
View Full Code Here

public class TokenConsumerTest extends TestCase {
  
   public void testTokenConsumer() throws IOException {
      Allocator allocator = new ArrayAllocator();
      TokenConsumer consumer = new TokenConsumer(allocator, "\r\n".getBytes());
      Cursor cursor = new StreamCursor("\r\n");
     
      consumer.consume(cursor);
     
      assertEquals(cursor.ready(), -1);
      assertTrue(consumer.isFinished())
   }
View Full Code Here

   }
  
   public void testTokenConsumerException() throws IOException {
      Allocator allocator = new ArrayAllocator();
      TokenConsumer consumer = new TokenConsumer(allocator, "\r\n".getBytes());
      Cursor cursor = new StreamCursor("--\r\n");
      boolean exception = false;
     
      try {
         consumer.consume(cursor);
      } catch(Exception e) {
View Full Code Here

   }
  
   public void testTokenConsumerDribble() throws IOException {
      Allocator allocator = new ArrayAllocator();
      TokenConsumer consumer = new TokenConsumer(allocator, "This is a large token to be consumed\r\n".getBytes());
      DribbleCursor cursor = new DribbleCursor(new StreamCursor("This is a large token to be consumed\r\n0123456789"), 1);

      consumer.consume(cursor);
     
      assertEquals(cursor.ready(), 1);
      assertTrue(consumer.isFinished());
View Full Code Here

      // Add the boundary to the request body
      buf.append("\r\n--");
      buf.append(new String(BOUNDARY, 0, BOUNDARY.length, "UTF-8"));
      buffer = new ArrayAllocator().allocate();
     
      DribbleCursor cursor = new DribbleCursor(new StreamCursor(buf.toString()), dribble);
     
      while(!consumer.isFinished()) {
         consumer.consume(cursor);
      }
      byte[] consumedBytes = buffer.encode("UTF-8").getBytes("UTF-8");
View Full Code Here

TOP

Related Classes of org.simpleframework.http.core.StreamCursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.