byte[] bodyarr = toByteArr(response.getEntity().getContent()); byte[] boundary = "*************boundary>>****************".getBytes(); ByteArrayInputStream bis = new ByteArrayInputStream(bodyarr); MultipartStream stream; stream = new MultipartStream(bis,boundary); boolean hasNextPart = stream.skipPreamble(); while (hasNextPart) { String header=stream.readHeaders(); String name = getNameFromHeader(header); //if data is image FileOutputStream outputStream = new FileOutputStream(name+".png"); stream.readBodyData(outputStream); hasNextPart = stream.readBoundary(); }
/** * Finds the beginning of the first <code>encapsulation</code>. * * @return <code>true</code> if an <code>encapsulation</code> was found in * the stream. * * @throws IOException if an i/o error occurs. */ public boolean skipPreamble() throws IOException { // First delimiter may be not preceeded with a CRLF. System.arraycopy(boundary, 2, boundary, 0, boundary.length - 2); boundaryLength = boundary.length - 2; try { // Discard all data up to the delimiter. discardBodyData(); // Read boundary - if succeeded, the stream contains an // encapsulation. return readBoundary(); } catch (MalformedStreamException e) { return false; } finally { // Restore delimiter. System.arraycopy(boundary, 0, boundary, 2, boundary.length - 2); boundaryLength = boundary.length; boundary[0] = CR; boundary[1] = LF; } }
/** * Called for finding the separator. */ private void findSeparator() { pos = MultipartStream.this.findSeparator(); if (pos == -1) { if (tail - head > keepRegion) { pad = keepRegion; } else { pad = tail - head; } } }
/** * Finds the beginning of the first <code>encapsulation</code>. * * @return <code>true</code> if an <code>encapsulation</code> was found in * the stream. * * @throws IOException if an i/o error occurs. */ public boolean skipPreamble() throws IOException { // First delimiter may be not preceded with a CRLF. System.arraycopy(boundary, 2, boundary, 0, boundary.length - 2); boundaryLength = boundary.length - 2; computeBoundaryTable(); try { // Discard all data up to the delimiter. discardBodyData(); // Read boundary - if succeeded, the stream contains an // encapsulation. return readBoundary(); } catch (MalformedStreamException e) { return false; } finally { // Restore delimiter. System.arraycopy(boundary, 0, boundary, 2, boundary.length - 2); boundaryLength = boundary.length; boundary[0] = CR; boundary[1] = LF; computeBoundaryTable(); } }
boolean nextPart; if (skipPreamble) { nextPart = multi.skipPreamble(); } else { nextPart = multi.readBoundary(); multi.setBoundary(boundary); currentFieldName = null; continue; FileItemHeaders headers = getParsedHeaders(multi.readHeaders()); if (currentFieldName == null) { multi.setBoundary(subBoundary); skipPreamble = true; continue; multi.discardBodyData();
MultipartStream multi = new MultipartStream(input, boundary); multi.setHeaderEncoding(headerEncoding); boolean nextPart = multi.skipPreamble(); while (nextPart) Map headers = parseHeaders(multi.readHeaders()); String fieldName = getFieldName(headers); if (fieldName != null) subContentType .indexOf("boundary=") + 9).getBytes(); multi.setBoundary(subBoundary); boolean nextSubPart = multi.skipPreamble(); while (nextSubPart) headers = parseHeaders(multi.readHeaders()); if (getFileName(headers) != null) multi.readBodyData(os); multi.discardBodyData(); nextSubPart = multi.readBoundary(); multi.setBoundary(boundary); multi.readBodyData(os);
try marker[0] = readByte(); marker[1] = readByte(); if (arrayequals(marker, STREAM_TERMINATOR, 2)) else if (arrayequals(marker, FIELD_SEPARATOR, 2))
multi = new MultipartStream(input, boundary, notifier); multi.setHeaderEncoding(charEncoding);
/** * <p> Reads <code>body-data</code> from the current * <code>encapsulation</code> and discards it. * * <p>Use this method to skip encapsulations you don't need or don't * understand. * * @return The amount of data discarded. * * @throws MalformedStreamException if the stream ends unexpectedly. * @throws IOException if an i/o error occurs. */ public int discardBodyData() throws MalformedStreamException, IOException { return readBodyData(null); }
b[0] = readByte();
boolean nextPart; if (skipPreamble) { nextPart = multi.skipPreamble(); } else { nextPart = multi.readBoundary(); multi.setBoundary(boundary); currentFieldName = null; continue; FileItemHeaders headers = getParsedHeaders(multi.readHeaders()); if (currentFieldName == null) { multi.setBoundary(subBoundary); skipPreamble = true; continue; multi.discardBodyData();
marker[0] = readByte(); if (marker[0] == LF) { marker[1] = readByte(); if (arrayequals(marker, STREAM_TERMINATOR, 2)) { nextChunk = false; } else if (arrayequals(marker, FIELD_SEPARATOR, 2)) { nextChunk = true; } else {
multi = new MultipartStream(input, boundary, notifier); multi.setHeaderEncoding(charEncoding);
/** * <p> Reads <code>body-data</code> from the current * <code>encapsulation</code> and discards it. * * <p>Use this method to skip encapsulations you don't need or don't * understand. * * @return The amount of data discarded. * * @throws MalformedStreamException if the stream ends unexpectedly. * @throws IOException if an i/o error occurs. */ public int discardBodyData() throws MalformedStreamException, IOException { return readBodyData(null); }
while (i < HEADER_SEPARATOR.length) { try { b = readByte(); } catch (FileUploadIOException e) {
boolean nextPart; if (skipPreamble) { nextPart = multi.skipPreamble(); } else { nextPart = multi.readBoundary(); multi.setBoundary(boundary); currentFieldName = null; continue; FileItemHeaders headers = getParsedHeaders(multi.readHeaders()); if (currentFieldName == null) { multi.setBoundary(subBoundary); skipPreamble = true; continue; multi.discardBodyData();
new MultipartStream(content, boundary); boolean nextPart = multipartStream.skipPreamble(); while (nextPart) { String header = multipartStream.readHeaders(); System.out.println(""); System.out.println("Headers:"); System.out.println(header); System.out.println("Body:"); multipartStream.readBodyData(System.out); System.out.println(""); nextPart = multipartStream.readBoundary();
marker[0] = readByte(); if (marker[0] == LF) { marker[1] = readByte(); if (arrayequals(marker, STREAM_TERMINATOR, 2)) { nextChunk = false; } else if (arrayequals(marker, FIELD_SEPARATOR, 2)) { nextChunk = true; } else {
/** * Finds the beginning of the first <code>encapsulation</code>. * * @return <code>true</code> if an <code>encapsulation</code> was found in * the stream. * * @throws IOException if an i/o error occurs. */ public boolean skipPreamble() throws IOException { // First delimiter may be not preceeded with a CRLF. System.arraycopy(boundary, 2, boundary, 0, boundary.length - 2); boundaryLength = boundary.length - 2; try { // Discard all data up to the delimiter. discardBodyData(); // Read boundary - if succeeded, the stream contains an // encapsulation. return readBoundary(); } catch (MalformedStreamException e) { return false; } finally { // Restore delimiter. System.arraycopy(boundary, 0, boundary, 2, boundary.length - 2); boundaryLength = boundary.length; boundary[0] = CR; boundary[1] = LF; } }
multi = new MultipartStream(input, boundary, notifier); } catch (IllegalArgumentException iae) { String.format("The boundary specified in the %s header is too long", CONTENT_TYPE), iae); multi.setHeaderEncoding(charEncoding);