private byte[] trimCRLF(byte[] bytes) { if (endsWithCRLF(bytes)) { return Arrays.copyOf(bytes, bytes.length - 2); } return bytes; }
private void drainInput() { try { input.skip(input.available()); } catch (IOException e) { rethrow(e); } }
public Part nextPart() { ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] line = readLine(input); if (isBoundaryLine(line)) { byte[] header = trimCRLF(readLine(input)); prevHeader = header; } else { Part part = new Part(trimCRLF(output.toByteArray()), prevHeader); prevHeader = header; return part; } else if (isEomBoundaryLine(line)) { drainInput(); if (firstPart) { return null; } else { return new Part(trimCRLF(output.toByteArray()), prevHeader); output.write(line); } catch (IOException e) { rethrow(e); line = readLine(input);
@Override protected ApplicationLogs readInternal(Class<? extends ApplicationLogs> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { String boundary = getMessageBoundary(inputMessage); Multipart multipart = new Multipart(inputMessage.getBody(), boundary); ApplicationLogs logs = new ApplicationLogs(); Multipart.Part part; while ((part = multipart.nextPart()) != null) { ApplicationLog log = messageParser.parseMessage(part.getContent()); logs.add(log); } return logs; }
public Part nextPart() { ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] line = readLine(input); if (isBoundaryLine(line)) { byte[] header = trimCRLF(readLine(input)); prevHeader = header; } else { Part part = new Part(trimCRLF(output.toByteArray()), prevHeader); prevHeader = header; return part; } else if (isEomBoundaryLine(line)) { drainInput(); if (firstPart) { return null; } else { return new Part(trimCRLF(output.toByteArray()), prevHeader); output.write(line); } catch (IOException e) { rethrow(e); line = readLine(input);
@Override protected ApplicationLogs readInternal(Class<? extends ApplicationLogs> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { String boundary = getMessageBoundary(inputMessage); Multipart multipart = new Multipart(inputMessage.getBody(), boundary); ApplicationLogs logs = new ApplicationLogs(); Multipart.Part part; while ((part = multipart.nextPart()) != null) { ApplicationLog log = messageParser.parseMessage(part.getContent()); logs.add(log); } return logs; }
private void drainInput() { try { input.skip(input.available()); } catch (IOException e) { rethrow(e); } }
private byte[] trimCRLF(byte[] bytes) { if (endsWithCRLF(bytes)) { return Arrays.copyOf(bytes, bytes.length - 2); } return bytes; }
private byte[] readLine(InputStream input) { byteBuffer.reset(); try { int value; while ((value = input.read()) != -1) { byteBuffer.write(value); if (value == '\n') { break; } } } catch (IOException e) { return rethrow(e); } return byteBuffer.toByteArray(); }
private byte[] readLine(InputStream input) { byteBuffer.reset(); try { int value; while ((value = input.read()) != -1) { byteBuffer.write(value); if (value == '\n') { break; } } } catch (IOException e) { return rethrow(e); } return byteBuffer.toByteArray(); }