@Override public MultiPartBody readFrom(Class<MultiPartBody> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { return new MultiPartBodyImpl(entityStream, mediaType); }
/** * Creates a MultiPartBody from the InputStream of the body and the MediaType * * @param rawIn * @param type * @throws HandlerException */ public MultiPartBodyImpl(final InputStream rawIn, final MediaType type) throws IOException { this(rawIn, getBoundary(type)); }
while (true) { Map<String, String> partHeaders; partHeaders = readHeaders(in); allFieldNames.add(disposition.name); if (disposition.getFileName() != null) { addFileField(disposition, (String) partHeaders .get(HttpHeaders.CONTENT_TYPE.toLowerCase(Locale.ENGLISH)).trim(), data); } else { addTextField(disposition, data);
/** * creates a MultiPartBody by parsing a stream * * @param rawIn * @param boundary * the boundary-string delimiting the parts * @throws HandlerException */ public MultiPartBodyImpl(final InputStream rawIn, final String boundary) throws IOException { rawCollection = new ArrayList<KeyValuePair<ParameterValue>>(); 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 }