void parseHeaders() { try { headers = HeadersParser.parseHeaders(new ByteArrayInputStream(headersByteArrayOutputStream.toByteArray()), multipartContext.getCharEncoding()); headersByteArrayOutputStream.reset(); } catch (Exception e) { goToState(State.ERROR); nioMultipartParserListener.onError("Error parsing the part headers", e); } }
void parseHeaders() { try { headers = HeadersParser.parseHeaders(new ByteArrayInputStream(headersByteArrayOutputStream.toByteArray()), multipartContext.getCharEncoding()); headersByteArrayOutputStream.reset(); } catch (Exception e) { goToState(State.ERROR); nioMultipartParserListener.onError("Error parsing the part headers", e); } }
void getReadyForNestedMultipart(final WriteContext wCtx) { if (delimiterPrefixes.size() > maxLevelOfNestedMultipart + 1) { goToState(State.ERROR); nioMultipartParserListener.onError("Reached maximum number of nested multiparts: " + maxLevelOfNestedMultipart, null); } else { byte[] delimiter = getDelimiterPrefix(MultipartUtils.getHeader(MultipartUtils.CONTENT_TYPE, headers)); delimiterType.reset(); delimiterPrefixes.push(delimiter); endOfLineBuffer.recycle(getPreambleDelimiterPrefix(delimiter), null); goToState(State.SKIP_PREAMBLE); nioMultipartParserListener.onNestedPartStarted(headers); } wCtx.setFinishedIfNoMoreData(); }
void getReadyForNestedMultipart(final WriteContext wCtx) { if (delimiterPrefixes.size() > maxLevelOfNestedMultipart + 1) { goToState(State.ERROR); nioMultipartParserListener.onError("Reached maximum number of nested multiparts: " + maxLevelOfNestedMultipart, null); } else { byte[] delimiter = getDelimiterPrefix(MultipartUtils.getHeader(MultipartUtils.CONTENT_TYPE, headers)); delimiterType.reset(); delimiterPrefixes.push(delimiter); endOfLineBuffer.recycle(getPreambleDelimiterPrefix(delimiter), null); goToState(State.SKIP_PREAMBLE); nioMultipartParserListener.onNestedPartStarted(headers); } wCtx.setFinishedIfNoMoreData(); }
void partComplete(final WriteContext wCtx){ // First flush the output stream and close it... try{ partBodyStreamStorage.flush(); partBodyStreamStorage.close(); }catch (Exception e){ goToState(State.ERROR); nioMultipartParserListener.onError("Unable to read/write the body data", e); return; } // Switch state if (delimiterType.getDelimiterType() == DelimiterType.Type.CLOSE){ if (delimiterPrefixes.size() > 1){ goToState(State.NESTED_PART_READ); }else { goToState(State.ALL_PARTS_READ); } }else { goToState(State.GET_READY_FOR_HEADERS); } nioMultipartParserListener.onPartFinished(partBodyStreamStorage, headers); partIndex++; wCtx.setFinishedIfNoMoreData(); }
void partComplete(final WriteContext wCtx){ // First flush the output stream and close it... try{ partBodyStreamStorage.flush(); partBodyStreamStorage.close(); }catch (Exception e){ goToState(State.ERROR); nioMultipartParserListener.onError("Unable to read/write the body data", e); return; } // Switch state if (delimiterType.getDelimiterType() == DelimiterType.Type.CLOSE){ if (delimiterPrefixes.size() > 1){ goToState(State.NESTED_PART_READ); }else { goToState(State.ALL_PARTS_READ); } }else { goToState(State.GET_READY_FOR_HEADERS); } nioMultipartParserListener.onPartFinished(partBodyStreamStorage, headers); partIndex++; wCtx.setFinishedIfNoMoreData(); }
void identifyDelimiter(final WriteContext wCtx, final State onDelimiter, final State onCloseDelimiter) { int byteOfData; while ((byteOfData = wCtx.read()) != -1) { delimiterType.addDelimiterByte((byte)byteOfData); if (delimiterType.index >= 2) { DelimiterType.Type type = delimiterType.getDelimiterType(); if (DelimiterType.Type.ENCAPSULATION == type) { goToState(onDelimiter); wCtx.setFinishedIfNoMoreData(); return; } else if (DelimiterType.Type.CLOSE == type) { goToState(onCloseDelimiter); // Need to continue because we encountered a close delimiter and we might not have more data coming // but we want to switch state and notify. wCtx.setNotFinished(); return; } else { goToState(State.ERROR); nioMultipartParserListener.onError("Unexpected characters follow a boundary", null); wCtx.setFinished(); return; } } } wCtx.setFinishedIfNoMoreData(); }
void identifyDelimiter(final WriteContext wCtx, final State onDelimiter, final State onCloseDelimiter) { int byteOfData; while ((byteOfData = wCtx.read()) != -1) { delimiterType.addDelimiterByte((byte)byteOfData); if (delimiterType.index >= 2) { DelimiterType.Type type = delimiterType.getDelimiterType(); if (DelimiterType.Type.ENCAPSULATION == type) { goToState(onDelimiter); wCtx.setFinishedIfNoMoreData(); return; } else if (DelimiterType.Type.CLOSE == type) { goToState(onCloseDelimiter); // Need to continue because we encountered a close delimiter and we might not have more data coming // but we want to switch state and notify. wCtx.setNotFinished(); return; } else { goToState(State.ERROR); nioMultipartParserListener.onError("Unexpected characters follow a boundary", null); wCtx.setFinished(); return; } } } wCtx.setFinishedIfNoMoreData(); }