Examples of DribbleCursor


Examples of org.simpleframework.http.core.DribbleCursor

      byte[] data = SOURCE.getBytes("UTF-8");
      byte[] boundary = "mxvercagiykxaqsdvrfabfhfpaseejrg".getBytes("UTF-8");
      Allocator allocator = new ArrayAllocator();
      FileUploadConsumer consumer = new FileUploadConsumer(allocator, boundary, data.length);     
      Cursor cursor = new StreamCursor(data);
      DribbleCursor dribble = new DribbleCursor(cursor, 1);
     
      while(!consumer.isFinished()) {
         consumer.consume(dribble);
     
      assertEquals(consumer.getBody().getContent(), SOURCE);
View Full Code Here

Examples of org.simpleframework.http.core.DribbleCursor

      byte[] data = SOURCE.getBytes("UTF-8");
      byte[] boundary = "mxvercagiykxaqsdvrfabfhfpaseejrg".getBytes("UTF-8");
      Allocator allocator = new ArrayAllocator();
      FileUploadConsumer consumer = new FileUploadConsumer(allocator, boundary, data.length);     
      Cursor cursor = new StreamCursor(data);
      DribbleCursor dribble = new DribbleCursor(cursor, 3);
     
      while(!consumer.isFinished()) {
         consumer.consume(dribble);
     
      assertEquals(consumer.getBody().getContent(), SOURCE);
View Full Code Here

Examples of org.simpleframework.http.core.DribbleCursor

      assertTrue(boundary.isEnd());
      assertFalse(cursor.isReady());
   }
  
   public void testDribble() throws Exception {
      DribbleCursor cursor = new DribbleCursor(new StreamCursor(new ByteArrayInputStream(TERMINAL)), 3);
     
      while(!boundary.isFinished()) {
         boundary.consume(cursor);
      }  
      assertEquals(cursor.read(), 'X');
      assertEquals(cursor.read(), 'Y');
      assertTrue(boundary.isFinished());
      assertTrue(boundary.isEnd());
      assertFalse(cursor.isReady());
     
      boundary.clear();
     
      cursor = new DribbleCursor(new StreamCursor(new ByteArrayInputStream(TERMINAL)), 1);
     
      while(!boundary.isFinished()) {
         boundary.consume(cursor);
      }  
      assertEquals(cursor.read(), 'X');
      assertEquals(cursor.read(), 'Y');
      assertTrue(boundary.isFinished());
      assertTrue(boundary.isEnd());
      assertFalse(cursor.isReady());
   }
View Full Code Here

Examples of org.simpleframework.http.core.DribbleCursor

      assertEquals(header.getContentType().getPrimary(), null);
      assertEquals(header.getContentType().getSecondary(), null);  
   }
  
   public void testDribble() throws Exception
      Cursor cursor = new DribbleCursor(new StreamCursor(SOURCE), 1);
     
      while(!header.isFinished()) {
         header.consume(cursor);
      }     
      assertEquals(cursor.ready(), -1);
      assertEquals(header.getValue("Content-Length"), "42");
      assertEquals(header.getValue("Content-Type"), "application/x-www-form-urlencoded");
      assertEquals(header.getValue("Host"), "some.host.com");
      assertEquals(header.getValues("Accept").size(), 4);
      assertEquals(header.getValues("Accept").get(0), "image/gif");
View Full Code Here

Examples of org.simpleframework.http.core.DribbleCursor

   }
  
   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);
      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

Examples of org.simpleframework.http.core.DribbleCursor

      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

Examples of org.simpleframework.http.core.DribbleCursor

   }
  
   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());
      assertEquals(cursor.read(), '0');
      assertEquals(cursor.read(), '1');
      assertEquals(cursor.read(), '2');
   }
View Full Code Here

Examples of org.simpleframework.http.core.DribbleCursor

      // 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");
      String consumedBody = new String(consumedBytes, 0, consumedBytes.length, "UTF-8");
     
      assertEquals(String.format("Failed for entitySize=%s and dribble=%s", entitySize, dribble), consumedBody, requestBody);
      assertEquals(cursor.read(), '\r');
      assertEquals(cursor.read(), '\n');
      assertEquals(cursor.read(), '-');
      assertEquals(cursor.read(), '-');
      assertEquals(cursor.read(), BOUNDARY[0]);
      assertEquals(cursor.read(), BOUNDARY[1]);
      assertEquals(consumer.getPart().getContentType().getPrimary(), "text");
      assertEquals(consumer.getPart().getContentType().getSecondary(), "plain");
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.