コード例 #1
0
  @Override
  public void ready(Collector collector) throws IOException {
    final Entity entity = collector;
    final Channel channel = entity.getChannel();
    final ByteCursor cursor = channel.getCursor();
    final Header header = entity.getHeader();
    final Body body = entity.getBody();
    final List<Part> list = body.getParts();

    AssertJUnit.assertEquals(header.getTarget(), "/index.html");
    AssertJUnit.assertEquals(header.getMethod(), "POST");
    AssertJUnit.assertEquals(header.getMajor(), 1);
    AssertJUnit.assertEquals(header.getMinor(), 0);
    AssertJUnit.assertEquals(header.getContentType().getPrimary(), "multipart");
    AssertJUnit.assertEquals(header.getContentType().getSecondary(), "form-data");
    AssertJUnit.assertEquals(header.getValue("Host"), "some.host.com");
    AssertJUnit.assertEquals(header.getValues("Accept").size(), 4);
    AssertJUnit.assertEquals(header.getValues("Accept").get(0), "image/gif");
    AssertJUnit.assertEquals(header.getValues("Accept").get(1), "image/png");
    AssertJUnit.assertEquals(header.getValues("Accept").get(2), "image/jpeg");
    AssertJUnit.assertEquals(header.getValues("Accept").get(3), "*");
    AssertJUnit.assertEquals(list.size(), 4);
    AssertJUnit.assertEquals(list.get(0).getContentType().getPrimary(), "text");
    AssertJUnit.assertEquals(list.get(0).getContentType().getSecondary(), "plain");
    AssertJUnit.assertEquals(
        list.get(0).getHeader("Content-Disposition"),
        "file; name=\"pics\"; filename=\"file1.txt\"; modification-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"");
    AssertJUnit.assertEquals(list.get(0).getName(), "pics");
    AssertJUnit.assertEquals(list.get(0).getFileName(), "file1.txt");
    AssertJUnit.assertEquals(list.get(0).isFile(), true);
    AssertJUnit.assertEquals(list.get(1).getContentType().getPrimary(), "text");
    AssertJUnit.assertEquals(list.get(1).getContentType().getSecondary(), "plain");
    AssertJUnit.assertEquals(
        list.get(1).getHeader("Content-Disposition"),
        "file; name=\"pics\"; filename=\"file2.txt\"");
    AssertJUnit.assertEquals(list.get(1).getContentType().getPrimary(), "text");
    AssertJUnit.assertEquals(list.get(1).getName(), "pics");
    AssertJUnit.assertEquals(list.get(1).getFileName(), "file2.txt");
    AssertJUnit.assertEquals(list.get(1).isFile(), true);
    AssertJUnit.assertEquals(list.get(2).getContentType().getSecondary(), "plain");
    AssertJUnit.assertEquals(
        list.get(2).getHeader("Content-Disposition"),
        "file; name=\"pics\"; filename=\"file3.txt\"");
    AssertJUnit.assertEquals(list.get(2).getName(), "pics");
    AssertJUnit.assertEquals(list.get(2).getFileName(), "file3.txt");
    AssertJUnit.assertEquals(list.get(2).isFile(), true);
    AssertJUnit.assertEquals(list.get(3).getContentType().getPrimary(), "text");
    AssertJUnit.assertEquals(list.get(3).getContentType().getSecondary(), "plain");
    AssertJUnit.assertEquals(
        list.get(3).getHeader("Content-Disposition"),
        "file; name=\"pics\"; filename=\"file4.txt\"");
    AssertJUnit.assertEquals(list.get(3).getName(), "pics");
    AssertJUnit.assertEquals(list.get(3).getFileName(), "file4.txt");
    AssertJUnit.assertEquals(list.get(3).isFile(), true);
    AssertJUnit.assertEquals(cursor.ready(), -1);
  }
コード例 #2
0
 /**
  * This is used to push the start and boundary back on to the cursor. Pushing the boundary back on
  * to the cursor is required to ensure that the next consumer will have valid data to read from
  * it. Simply resetting the boundary is not enough as this can cause an infinite loop if the
  * connection is bad.
  *
  * @param cursor this is the cursor used by this consumer
  */
 @Override
 protected void commit(ByteCursor cursor) throws IOException {
   cursor.push(boundary);
   cursor.push(START);
 }