title: Jetty throws exception : 'Buffer size exceeded: no line terminator' when using getParts
body: <p>I am trying to upload a file. In the servlet when I call getParts() on request, I am getting the below error :</p>
  
  <pre><code>java.io.IOException: Buffer size exceeded: no line terminator
      at org.eclipse.jetty.util.ReadLineInputStream.readLine(ReadLineInputStream.java:55)
      at org.eclipse.jetty.util.MultiPartInputStreamParser.parse(MultiPartInputStreamParser.java:487)
      at org.eclipse.jetty.util.MultiPartInputStreamParser.getParts(MultiPartInputStreamParser.java:405)
      at org.eclipse.jetty.server.Request.getParts(Request.java:2311)
      at org.eclipse.jetty.server.Request.getParts(Request.java:2290)
  </code></pre>
  
  <p>Any idea how to resolve this error ? I researched a lot and also implemented a lot of solutions, but nothing is working. </p>
  
  <p>Annotated servlet with following annotation:</p>
  
  <pre><code>@MultipartConfig
  </code></pre>
  
  <p>When starting Jetty, added following configurations to server: (seems like TagLibConfiguration is not available in version 9.3.6.v20151106)</p>
  
  <pre><code>WebAppContext root = new WebAppContext();
      root.setConfigurations(new Configuration[] {
              new AnnotationConfiguration(), new WebXmlConfiguration(),
              new WebInfConfiguration(), //new TagLibConfiguration(),
              new PlusConfiguration(), new MetaInfConfiguration(),
              new JettyWebXmlConfiguration(),
              new FragmentConfiguration(), new EnvConfiguration() });
              ....
              ....
  
              ServletHolder clientServletHolder = new ServletHolder(new ClientServlet(lwServer, lwServer.getSecureAddress()
                              .getPort()));
              clientServletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(System.getProperty("java.io.tmpdir")));
              ....
              ....
  </code></pre>
  
  <p>The file that I am uploading is a binary file. </p>
  
  <p>If I try below </p>
  
  <pre><code>            String content = IOUtils.toString(req.getInputStream(), parameters.get("charset"));
              byte[] byteArray = content.getBytes();
              System.out.println("content len : " + content.length() + "   byteArray size : " + byteArray.length);
  
              The output is 
  
              content len : 46934   byteArray size : 52864
  </code></pre>
  
  <p>And when I do a file comparison the content does not match.         </p>
  
  <p>The contents don't match for below either. The charset I believe is 'UTF-8'.</p>
  
  <pre><code>File saveFile = new File("C:\\test\\downloadedFile.bin");
              // opens input stream of the request for reading data
              InputStream inputStream = req.getInputStream();
  
              // opens an output stream for writing file
              FileOutputStream outputStream = new FileOutputStream(saveFile);
  
              byte[] buffer = new byte[100000];
              int bytesRead = -1;
              System.out.println("Receiving data...");
  
              while ((bytesRead = inputStream.read(buffer)) != -1) {
                  outputStream.write(buffer, 0, bytesRead);
              }
  
              System.out.println("Data received.");
              outputStream.close();
              inputStream.close();
  </code></pre>
  
  <p>AngularJS code is as follows:</p>
  
  <pre><code>$('#uploadFileSubmit').click(function(e) {
                      e.preventDefault();
                      var value = $('#uploadFileInputValue').val();
  
                      var f = document.getElementById('uploadFileInputValue').files[0];
                      var r = new FileReader();
                      var fileContent;
                      r.onloadend = function(e){
                          fileContent = e.target.result;
                      };
                      r.readAsBinaryString(f);
                      alert("hi !!")
                      if(value) {
                          $('#uploadFileModal').modal('hide');
  
                          var rsc = {};
                          rsc["id"] = scope.resource.def.id;
                          value = lwResources.getTypedValue(fileContent, scope.resource.def.type);
                          rsc["value"] = value;
  
                          $http({method: 'PUT', url: "api/clients/" + $routeParams.clientId + scope.resource.path, data: rsc, timeout:300000, headers:{'Content-Type': 'multipart/form-data'}})
                              .success(function(data, status, headers, config) { .... }
                              .error(function(data, status, headers, config) {....});;
  </code></pre>
  
  <p>But nothing seems to resolve the error. Any idea how to resolve this error ?     </p>