Skip to content

Commit

Permalink
Issue jetty#4368 - make MultiParts a class instead of interface
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Nov 27, 2019
1 parent 37eeecf commit e9ad3dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 47 deletions.
73 changes: 27 additions & 46 deletions jetty-server/src/main/java/org/eclipse/jetty/server/MultiParts.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,59 +30,40 @@
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandler.Context;

/*
* Used to switch between the old and new implementation of MultiPart Form InputStream Parsing.
* The new implementation is preferred will be used as default unless specified otherwise constructor.
*/
public interface MultiParts extends Closeable
public class MultiParts implements Closeable
{
Collection<Part> getParts() throws IOException;
private final MultiPartFormInputStream _httpParser;
private final ContextHandler.Context _context;

Part getPart(String name) throws IOException;

boolean isEmpty();

ContextHandler.Context getContext();

class MultiPartsHttpParser implements MultiParts
public MultiParts(InputStream in, String contentType, MultipartConfigElement config, File contextTmpDir, Request request)
{
private final MultiPartFormInputStream _httpParser;
private final ContextHandler.Context _context;

public MultiPartsHttpParser(InputStream in, String contentType, MultipartConfigElement config, File contextTmpDir, Request request) throws IOException
{
_httpParser = new MultiPartFormInputStream(in, contentType, config, contextTmpDir);
_context = request.getContext();
}
_httpParser = new MultiPartFormInputStream(in, contentType, config, contextTmpDir);
_context = request.getContext();
}

@Override
public Collection<Part> getParts() throws IOException
{
return _httpParser.getParts();
}
public Collection<Part> getParts() throws IOException
{
return _httpParser.getParts();
}

@Override
public Part getPart(String name) throws IOException
{
return _httpParser.getPart(name);
}
public Part getPart(String name) throws IOException
{
return _httpParser.getPart(name);
}

@Override
public void close()
{
_httpParser.deleteParts();
}
@Override
public void close()
{
_httpParser.deleteParts();
}

@Override
public boolean isEmpty()
{
return _httpParser.isEmpty();
}
public boolean isEmpty()
{
return _httpParser.isEmpty();
}

@Override
public Context getContext()
{
return _context;
}
public Context getContext()
{
return _context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2379,7 +2379,7 @@ else if (getCharacterEncoding() != null)

private MultiParts newMultiParts(MultipartConfigElement config) throws IOException
{
return new MultiParts.MultiPartsHttpParser(getInputStream(), getContentType(), config,
return new MultiParts(getInputStream(), getContentType(), config,
(_context != null ? (File)_context.getAttribute("javax.servlet.context.tempdir") : null), this);
}

Expand Down

0 comments on commit e9ad3dd

Please sign in to comment.