@Test(expected = IOException.class) public void exceptionIsThrownOnUnexpectedEnd() throws IOException { when(request.getInputStream()).thenReturn(createInputStream("")); when(request.getHeader("Content-Length")).thenReturn("1"); handler.doHandleSimpleMultipartFileUpload(null, request, null, null, null, null, null); }
protected void doHandleSimpleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, String boundary) throws IOException { final InputStream inputStream = request.getInputStream(); long contentLength = getContentLength(request); boolean atStart = false; boolean firstFileFieldFound = false; String rawfilename = "unknown"; String rawMimeType = "application/octet-stream"; while (!atStart) { String readLine = readLine(inputStream); contentLength -= (readLine.getBytes(UTF8).length + CRLF.length()); if (readLine.startsWith("Content-Disposition:") && readLine.indexOf("filename=") > 0) { rawfilename = readLine.replaceAll(".*filename=", ""); char quote = rawfilename.charAt(0); rawfilename = rawfilename.substring(1); rawfilename = rawfilename.substring(0, rawfilename.indexOf(quote)); firstFileFieldFound = true; } else if (firstFileFieldFound && readLine.equals("")) { atStart = true; } else if (readLine.startsWith("Content-Type")) { rawMimeType = readLine.split(": ")[1]; } } contentLength -= (boundary.length() + CRLF.length() + 2 * DASHDASH.length() + CRLF.length()); InputStream simpleMultiPartReader = new SimpleMultiPartInputStream( inputStream, boundary); final String filename = removePath(rawfilename); final String mimeType = rawMimeType; try { handleFileUploadValidationAndData(session, simpleMultiPartReader, streamVariable, filename, mimeType, contentLength, owner, variableName); } catch (UploadException e) { session.getCommunicationManager().handleConnectorRelatedException( owner, e); } sendUploadResponse(request, response); }
FileUploadHandler implements RequestHandler { protected void doHandleSimpleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, String boundary) throws IOException { final InputStream inputStream = request.getInputStream(); long contentLength = getContentLength(request); boolean atStart = false; boolean firstFileFieldFound = false; String rawfilename = "unknown"; String rawMimeType = "application/octet-stream"; while (!atStart) { String readLine = readLine(inputStream); contentLength -= (readLine.getBytes(UTF8).length + CRLF.length()); if (readLine.startsWith("Content-Disposition:") && readLine.indexOf("filename=") > 0) { rawfilename = readLine.replaceAll(".*filename=", ""); char quote = rawfilename.charAt(0); rawfilename = rawfilename.substring(1); rawfilename = rawfilename.substring(0, rawfilename.indexOf(quote)); firstFileFieldFound = true; } else if (firstFileFieldFound && readLine.equals("")) { atStart = true; } else if (readLine.startsWith("Content-Type")) { rawMimeType = readLine.split(": ")[1]; } } contentLength -= (boundary.length() + CRLF.length() + 2 * DASHDASH.length() + CRLF.length()); InputStream simpleMultiPartReader = new SimpleMultiPartInputStream( inputStream, boundary); final String filename = removePath(rawfilename); final String mimeType = rawMimeType; try { handleFileUploadValidationAndData(session, simpleMultiPartReader, streamVariable, filename, mimeType, contentLength, owner, variableName); } catch (UploadException e) { session.getCommunicationManager().handleConnectorRelatedException( owner, e); } sendUploadResponse(request, response); } }
FileUploadHandler implements RequestHandler { protected void doHandleSimpleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, String boundary) throws IOException { final InputStream inputStream = request.getInputStream(); long contentLength = getContentLength(request); boolean atStart = false; boolean firstFileFieldFound = false; String rawfilename = "unknown"; String rawMimeType = "application/octet-stream"; while (!atStart) { String readLine = readLine(inputStream); contentLength -= (readLine.getBytes(UTF8).length + CRLF.length()); if (readLine.startsWith("Content-Disposition:") && readLine.indexOf("filename=") > 0) { rawfilename = readLine.replaceAll(".*filename=", ""); char quote = rawfilename.charAt(0); rawfilename = rawfilename.substring(1); rawfilename = rawfilename.substring(0, rawfilename.indexOf(quote)); firstFileFieldFound = true; } else if (firstFileFieldFound && readLine.equals("")) { atStart = true; } else if (readLine.startsWith("Content-Type")) { rawMimeType = readLine.split(": ")[1]; } } contentLength -= (boundary.length() + CRLF.length() + 2 * DASHDASH.length() + CRLF.length()); InputStream simpleMultiPartReader = new SimpleMultiPartInputStream( inputStream, boundary); final String filename = removePath(rawfilename); final String mimeType = rawMimeType; try { handleFileUploadValidationAndData(session, simpleMultiPartReader, streamVariable, filename, mimeType, contentLength, owner, variableName); } catch (UploadException e) { session.getCommunicationManager().handleConnectorRelatedException( owner, e); } sendUploadResponse(request, response); }  }
FileUploadHandler implements RequestHandler { protected void doHandleSimpleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, String boundary) throws IOException { final InputStream inputStream = request.getInputStream(); long contentLength = getContentLength(request); boolean atStart = false; boolean firstFileFieldFound = false; String rawfilename = "unknown"; String rawMimeType = "application/octet-stream"; while (!atStart) { String readLine = readLine(inputStream); contentLength -= (readLine.getBytes(UTF8).length + CRLF.length()); if (readLine.startsWith("Content-Disposition:") && readLine.indexOf("filename=") > 0) { rawfilename = readLine.replaceAll(".*filename=", ""); char quote = rawfilename.charAt(0); rawfilename = rawfilename.substring(1); rawfilename = rawfilename.substring(0, rawfilename.indexOf(quote)); firstFileFieldFound = true; } else if (firstFileFieldFound && readLine.equals("")) { atStart = true; } else if (readLine.startsWith("Content-Type")) { rawMimeType = readLine.split(": ")[1]; } } contentLength -= (boundary.length() + CRLF.length() + 2 * DASHDASH.length() + CRLF.length()); InputStream simpleMultiPartReader = new SimpleMultiPartInputStream( inputStream, boundary); final String filename = removePath(rawfilename); final String mimeType = rawMimeType; try { handleFileUploadValidationAndData(session, simpleMultiPartReader, streamVariable, filename, mimeType, contentLength, owner, variableName); } catch (UploadException e) { session.getCommunicationManager().handleConnectorRelatedException( owner, e); } sendUploadResponse(request, response); }  @Override boolean handleRequest(VaadinSession session, VaadinRequest request,
            VaadinResponse response); }
FileUploadHandler implements RequestHandler { protected void doHandleSimpleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, String boundary) throws IOException { final InputStream inputStream = request.getInputStream(); long contentLength = getContentLength(request); boolean atStart = false; boolean firstFileFieldFound = false; String rawfilename = "unknown"; String rawMimeType = "application/octet-stream"; while (!atStart) { String readLine = readLine(inputStream); contentLength -= (readLine.getBytes(UTF8).length + CRLF.length()); if (readLine.startsWith("Content-Disposition:") && readLine.indexOf("filename=") > 0) { rawfilename = readLine.replaceAll(".*filename=", ""); char quote = rawfilename.charAt(0); rawfilename = rawfilename.substring(1); rawfilename = rawfilename.substring(0, rawfilename.indexOf(quote)); firstFileFieldFound = true; } else if (firstFileFieldFound && readLine.equals("")) { atStart = true; } else if (readLine.startsWith("Content-Type")) { rawMimeType = readLine.split(": ")[1]; } } contentLength -= (boundary.length() + CRLF.length() + 2 * DASHDASH.length() + CRLF.length()); InputStream simpleMultiPartReader = new SimpleMultiPartInputStream( inputStream, boundary); final String filename = removePath(rawfilename); final String mimeType = rawMimeType; try { handleFileUploadValidationAndData(session, simpleMultiPartReader, streamVariable, filename, mimeType, contentLength, owner, variableName); } catch (UploadException e) { session.getCommunicationManager().handleConnectorRelatedException( owner, e); } sendUploadResponse(request, response); }  @Override boolean handleRequest(VaadinSession session, VaadinRequest request,
            VaadinResponse response); static final int DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS; }