}
InputStream rawIn;
try {
rawIn = (InputStream) request.getBody();
} catch (ClassCastException ex) {
throw new HandlerException("request body is of type "+request.getBody().getClass(), ex);
}
DelimiterInputStream in = new DelimiterInputStream(rawIn);
ByteArrayOutputStream delimiterBaos = new ByteArrayOutputStream();
delimiterBaos.write(45);//dash
delimiterBaos.write(45);
delimiterBaos.write(boundary.getBytes("utf-8"));
byte[] delimiter = delimiterBaos.toByteArray();
in.readTill(delimiter);
in.read(); //13
in.read(); //10
delimiterBaos = new ByteArrayOutputStream();
delimiterBaos.write(LINE_BREAK);
delimiterBaos.write(delimiter);
readFields(in, delimiterBaos.toByteArray());
//from rfc 2616: a bare CR
//or LF MUST NOT be substituted for CRLF within any of the HTTP
// control
//structures (such as header fields and multipart boundaries)
//this means we are strict in expecting CRLF
} catch (IOException e) {
throw new HandlerException(e);
}
}