Package org.simpleframework.http.message

Examples of org.simpleframework.http.message.ContentConsumer


   }
  
   public void testContent(int entitySize, int dribble) throws Exception {
      MockSegment segment = new MockSegment();
      PartData list = new PartData();
      ContentConsumer consumer = new ContentConsumer(this, segment, list, BOUNDARY);
      StringBuffer buf = new StringBuffer();
     
      segment.add("Content-Disposition", "form-data; name='photo'; filename='photo.jpg'");
      segment.add("Content-Type", "text/plain");
      segment.add("Content-ID", "<IDENTITY>");
     
      for(int i = 0, line = 0; buf.length() < entitySize; i++) {
         String text = String.valueOf(i);       
       
         line += text.length();
         buf.append(text);
        
         if(line >= 48) {
            buf.append("\n");          
            line = 0;
         }
      }
      // Get request body without boundary
      String requestBody = buf.toString();
     
      // 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

Related Classes of org.simpleframework.http.message.ContentConsumer

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.