");
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
index f18c2498e0ea..069f22bbbb04 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
@@ -183,6 +183,43 @@ protected void generateAcceptableResponse(Request baseRequest, HttpServletReques
baseRequest.getResponse().closeOutput();
}
+ /**
+ * Generate an acceptable error response for a mime type.
+ * This method is called for each mime type in the users agent's
+ * Accept header, until {@link Request#isHandled()} is true and a
+ * response of the appropriate type is generated.
+ *
+ * @param baseRequest The base request
+ * @param request The servlet request (may be wrapped)
+ * @param response The response (may be wrapped)
+ * @param code the http error code
+ * @param message the http error message
+ * @param mimeType The mimetype to generate (may be */*or other wildcard)
+ * @throws IOException if a response cannot be generated
+ */
+ protected void generateAcceptableResponse(Request baseRequest, HttpServletRequest request, HttpServletResponse response, int code, String message, String mimeType)
+ throws IOException
+ {
+ switch (mimeType)
+ {
+ case "text/html":
+ case "text/*":
+ case "*/*":
+ {
+ baseRequest.setHandled(true);
+ Writer writer = getAcceptableWriter(baseRequest, request, response);
+ if (writer != null)
+ {
+ response.setContentType(MimeTypes.Type.TEXT_HTML.asString());
+ handleErrorPage(request, writer, code, message);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
/**
* Returns an acceptable writer for an error page.
* Uses the user-agent's Accept-Charset to get response
@@ -229,40 +266,6 @@ protected Writer getAcceptableWriter(Request baseRequest, HttpServletRequest req
return null;
}
- /**
- * Generate an acceptable error response for a mime type.
- * This method is called for each mime type in the users agent's
- * Accept header, until {@link Request#isHandled()} is true and a
- * response of the appropriate type is generated.
- *
- * @param baseRequest The base request
- * @param request The servlet request (may be wrapped)
- * @param response The response (may be wrapped)
- * @param code the http error code
- * @param message the http error message
- * @param mimeType The mimetype to generate (may be */*or other wildcard)
- * @throws IOException if a response cannot be generated
- */
- protected void generateAcceptableResponse(Request baseRequest, HttpServletRequest request, HttpServletResponse response, int code, String message, String mimeType)
- throws IOException
- {
- switch (mimeType)
- {
- case "text/html":
- case "text/*":
- case "*/*":
- {
- baseRequest.setHandled(true);
- Writer writer = getAcceptableWriter(baseRequest, request, response);
- if (writer != null)
- {
- response.setContentType(MimeTypes.Type.TEXT_HTML.asString());
- handleErrorPage(request, writer, code, message);
- }
- }
- }
- }
-
protected void handleErrorPage(HttpServletRequest request, Writer writer, int code, String message)
throws IOException
{
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java
index ccaf09adaff9..0c5a9705aba7 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java
@@ -105,7 +105,7 @@ public void onComplete(AsyncEvent event) throws IOException
Request request = state.getBaseRequest();
final long elapsed = System.currentTimeMillis() - request.getTimeStamp();
- long d = _requestStats.decrement();
+ final long d = _requestStats.decrement();
_requestTimeStats.record(elapsed);
updateResponse(request);
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ThreadLimitHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ThreadLimitHandler.java
index 6107087db224..7666bcb0641b 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ThreadLimitHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ThreadLimitHandler.java
@@ -126,6 +126,26 @@ public int getThreadLimit()
return _threadLimit;
}
+ protected int getThreadLimit(String ip)
+ {
+ if (!_includeExcludeSet.isEmpty())
+ {
+ try
+ {
+ if (!_includeExcludeSet.test(InetAddress.getByName(ip)))
+ {
+ LOG.debug("excluded {}", ip);
+ return 0;
+ }
+ }
+ catch (Exception e)
+ {
+ LOG.ignore(e);
+ }
+ }
+ return _threadLimit;
+ }
+
public void setThreadLimit(int threadLimit)
{
if (threadLimit <= 0)
@@ -221,26 +241,6 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
}
}
- protected int getThreadLimit(String ip)
- {
- if (!_includeExcludeSet.isEmpty())
- {
- try
- {
- if (!_includeExcludeSet.test(InetAddress.getByName(ip)))
- {
- LOG.debug("excluded {}", ip);
- return 0;
- }
- }
- catch (Exception e)
- {
- LOG.ignore(e);
- }
- }
- return _threadLimit;
- }
-
protected Remote getRemote(Request baseRequest)
{
Remote remote = (Remote)baseRequest.getAttribute(REMOTE);
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java
index c273befb6cff..ac10d9b324cc 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java
@@ -590,8 +590,8 @@ public void setInflateBufferSize(int size)
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
- ServletContext context = baseRequest.getServletContext();
- String path = context == null ? baseRequest.getRequestURI() : URIUtil.addPaths(baseRequest.getServletPath(), baseRequest.getPathInfo());
+ final ServletContext context = baseRequest.getServletContext();
+ final String path = context == null ? baseRequest.getRequestURI() : URIUtil.addPaths(baseRequest.getServletPath(), baseRequest.getPathInfo());
LOG.debug("{} handle {} in {}", this, baseRequest, context);
if (!_dispatchers.contains(baseRequest.getDispatcherType()))
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java
index 18ecfbaa66f1..62830cd60fe2 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java
@@ -110,6 +110,28 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements
*/
public abstract Session newSession(HttpServletRequest request, SessionData data);
+ /**
+ * @see org.eclipse.jetty.server.session.SessionCache#newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long)
+ */
+ @Override
+ public Session newSession(HttpServletRequest request, String id, long time, long maxInactiveMs)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Creating new session id=" + id);
+ Session session = newSession(request, _sessionDataStore.newSessionData(id, time, time, time, maxInactiveMs));
+ session.getSessionData().setLastNode(_context.getWorkerName());
+ try
+ {
+ if (isSaveOnCreate() && _sessionDataStore != null)
+ _sessionDataStore.store(id, session.getSessionData());
+ }
+ catch (Exception e)
+ {
+ LOG.warn("Save of new session {} failed", id, e);
+ }
+ return session;
+ }
+
/**
* Get the session matching the key
*
@@ -718,7 +740,7 @@ protected void renewSessionId(Session session, String newId, String newExtendedI
try (Lock lock = session.lock())
{
- String oldId = session.getId();
+ final String oldId = session.getId();
session.checkValidForWrite(); //can't change id on invalid session
session.getSessionData().setId(newId);
session.getSessionData().setLastSaved(0); //pretend that the session has never been saved before to get a full save
@@ -761,28 +783,6 @@ public boolean isSaveOnInactiveEviction()
return _saveOnInactiveEviction;
}
- /**
- * @see org.eclipse.jetty.server.session.SessionCache#newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long)
- */
- @Override
- public Session newSession(HttpServletRequest request, String id, long time, long maxInactiveMs)
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Creating new session id=" + id);
- Session session = newSession(request, _sessionDataStore.newSessionData(id, time, time, time, maxInactiveMs));
- session.getSessionData().setLastNode(_context.getWorkerName());
- try
- {
- if (isSaveOnCreate() && _sessionDataStore != null)
- _sessionDataStore.store(id, session.getSessionData());
- }
- catch (Exception e)
- {
- LOG.warn("Save of new session {} failed", id, e);
- }
- return session;
- }
-
@Override
public String toString()
{
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java
index a23ac240a341..b0f9c7df8afa 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java
@@ -601,15 +601,15 @@ protected SessionData load(InputStream is, String expectedId)
DataInputStream di = new DataInputStream(is);
id = di.readUTF();
- String contextPath = di.readUTF();
- String vhost = di.readUTF();
- String lastNode = di.readUTF();
- long created = di.readLong();
- long accessed = di.readLong();
- long lastAccessed = di.readLong();
- long cookieSet = di.readLong();
- long expiry = di.readLong();
- long maxIdle = di.readLong();
+ final String contextPath = di.readUTF();
+ final String vhost = di.readUTF();
+ final String lastNode = di.readUTF();
+ final long created = di.readLong();
+ final long accessed = di.readLong();
+ final long lastAccessed = di.readLong();
+ final long cookieSet = di.readLong();
+ final long expiry = di.readLong();
+ final long maxIdle = di.readLong();
data = newSessionData(id, created, accessed, lastAccessed, maxIdle);
data.setContextPath(contextPath);
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java
index 2f5a9d8cefd7..57a041c9ccc5 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java
@@ -234,6 +234,11 @@ public void setDirty(boolean dirty)
_dirty = dirty;
}
+ public void setDirty(String name)
+ {
+ setDirty(true);
+ }
+
/**
* @param name the name of the attribute
* @return the value of the attribute named
@@ -261,11 +266,6 @@ public Object setAttribute(String name, Object value)
return old;
}
- public void setDirty(String name)
- {
- setDirty(true);
- }
-
public void putAllAttributes(Map attributes)
{
_attributes.putAll(attributes);
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java
index e5dbf1a3579d..92a2ee85e8b2 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java
@@ -146,6 +146,8 @@ public String getErrorPage(HttpServletRequest request)
dbg.append(" (from global default)");
LOG.debug(dbg.toString());
break;
+ default:
+ throw new IllegalStateException(pageSource.toString());
}
}
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java
index 54fe628f0bd0..688b8785cbbc 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java
@@ -85,8 +85,9 @@ public static int dispatch(DispatcherType type)
return INCLUDE;
case ERROR:
return ERROR;
+ default:
+ throw new IllegalStateException(type.toString());
}
- throw new IllegalArgumentException(type.toString());
}
/**
@@ -109,8 +110,9 @@ public static DispatcherType dispatch(int type)
return DispatcherType.INCLUDE;
case ERROR:
return DispatcherType.ERROR;
+ default:
+ throw new IllegalArgumentException(Integer.toString(type));
}
- throw new IllegalArgumentException(Integer.toString(type));
}
private int _dispatches = DEFAULT;
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java
index 99c413691e18..6875d45cd023 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java
@@ -109,6 +109,16 @@ public static ServletContextHandler getServletContextHandler(ServletContext serv
return (ServletContextHandler)contextHandler;
}
+ public static ServletContextHandler getServletContextHandler(ServletContext context)
+ {
+ ContextHandler handler = getContextHandler(context);
+ if (handler == null)
+ return null;
+ if (handler instanceof ServletContextHandler)
+ return (ServletContextHandler)handler;
+ return null;
+ }
+
public interface ServletContainerInitializerCaller extends LifeCycle {}
;
@@ -721,16 +731,6 @@ void destroyFilter(Filter filter)
_objFactory.destroy(filter);
}
- public static ServletContextHandler getServletContextHandler(ServletContext context)
- {
- ContextHandler handler = getContextHandler(context);
- if (handler == null)
- return null;
- if (handler instanceof ServletContextHandler)
- return (ServletContextHandler)handler;
- return null;
- }
-
public static class JspPropertyGroup implements JspPropertyGroupDescriptor
{
private List _urlPatterns = new ArrayList();
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java
index 7a4fe6cc3039..091228801310 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java
@@ -384,7 +384,7 @@ protected void doFilter(HttpServletRequest request, HttpServletResponse response
long throttleMs = getThrottleMs();
if (!Boolean.TRUE.equals(throttled) && throttleMs > 0)
{
- int priority = getPriority(request, tracker);
+ final int priority = getPriority(request, tracker);
request.setAttribute(__THROTTLED, Boolean.TRUE);
if (isInsertHeaders())
response.addHeader("DoSFilter", "throttled");
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/IncludeExcludeBasedFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/IncludeExcludeBasedFilter.java
index a4ab6fe61506..5c9cc0db870d 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/IncludeExcludeBasedFilter.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/IncludeExcludeBasedFilter.java
@@ -77,12 +77,12 @@ public abstract class IncludeExcludeBasedFilter implements Filter
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
- String includedPaths = filterConfig.getInitParameter("includedPaths");
- String excludedPaths = filterConfig.getInitParameter("excludedPaths");
- String includedMimeTypes = filterConfig.getInitParameter("includedMimeTypes");
- String excludedMimeTypes = filterConfig.getInitParameter("excludedMimeTypes");
- String includedHttpMethods = filterConfig.getInitParameter("includedHttpMethods");
- String excludedHttpMethods = filterConfig.getInitParameter("excludedHttpMethods");
+ final String includedPaths = filterConfig.getInitParameter("includedPaths");
+ final String excludedPaths = filterConfig.getInitParameter("excludedPaths");
+ final String includedMimeTypes = filterConfig.getInitParameter("includedMimeTypes");
+ final String excludedMimeTypes = filterConfig.getInitParameter("excludedMimeTypes");
+ final String includedHttpMethods = filterConfig.getInitParameter("includedHttpMethods");
+ final String excludedHttpMethods = filterConfig.getInitParameter("excludedHttpMethods");
if (includedPaths != null)
{
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java
index a7856be8eda6..857d0183bda6 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java
@@ -243,7 +243,7 @@ public void listConfig(StartArgs args)
public void listModules(StartArgs args)
{
- List tags = args.getListModules();
+ final List tags = args.getListModules();
StartLog.endStartLog();
System.out.println();
@@ -275,7 +275,6 @@ public StartArgs processCommandLine(List cmdLine) throws Exception
public StartArgs processCommandLine(String[] cmdLine) throws Exception
{
// Processing Order is important!
- // ------------------------------------------------------------
// 1) Configuration Locations
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
baseHome = new BaseHome(cmdLineSource);
@@ -283,7 +282,6 @@ public StartArgs processCommandLine(String[] cmdLine) throws Exception
StartLog.debug("jetty.home=%s", baseHome.getHome());
StartLog.debug("jetty.base=%s", baseHome.getBase());
- // ------------------------------------------------------------
// 2) Parse everything provided.
// This would be the directory information +
// the various start inis
@@ -306,13 +304,11 @@ public StartArgs processCommandLine(String[] cmdLine) throws Exception
normalizeURI(baseHome.getBasePath().toUri().toString()),
base.source);
- // ------------------------------------------------------------
// 3) Module Registration
Modules modules = new Modules(baseHome, args);
StartLog.debug("Registering all modules");
modules.registerAll();
- // ------------------------------------------------------------
// 4) Active Module Resolution
for (String enabledModule : args.getEnabledModules())
{
@@ -343,21 +339,17 @@ public StartArgs processCommandLine(String[] cmdLine) throws Exception
module.setSkipFilesValidation(true);
}
- // ------------------------------------------------------------
// 5) Lib & XML Expansion / Resolution
args.expandSystemProperties();
args.expandLibs();
args.expandModules(activeModules);
- // ------------------------------------------------------------
// 6) Resolve Extra XMLs
args.resolveExtraXmls();
- // ------------------------------------------------------------
// 7) JPMS Expansion
args.expandJPMS(activeModules);
- // ------------------------------------------------------------
// 8) Resolve Property Files
args.resolvePropertyFiles();
@@ -497,12 +489,18 @@ public void run()
}
}
+ /* implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy) */
+ public void start() throws Exception
+ {
+ start(jsvcStartArgs);
+ }
+
private void doStop(StartArgs args)
{
- Prop stopHostProp = args.getProperties().getProp("STOP.HOST", true);
- Prop stopPortProp = args.getProperties().getProp("STOP.PORT", true);
- Prop stopKeyProp = args.getProperties().getProp("STOP.KEY", true);
- Prop stopWaitProp = args.getProperties().getProp("STOP.WAIT", true);
+ final Prop stopHostProp = args.getProperties().getProp("STOP.HOST", true);
+ final Prop stopPortProp = args.getProperties().getProp("STOP.PORT", true);
+ final Prop stopKeyProp = args.getProperties().getProp("STOP.KEY", true);
+ final Prop stopWaitProp = args.getProperties().getProp("STOP.WAIT", true);
String stopHost = "127.0.0.1";
int stopPort = -1;
@@ -611,6 +609,12 @@ public void stop(String host, int port, String key, int timeout)
}
}
+ /* implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy) */
+ public void stop() throws Exception
+ {
+ doStop(jsvcStartArgs);
+ }
+
public void usage(boolean exit)
{
StartLog.endStartLog();
@@ -655,8 +659,7 @@ public static boolean printTextResource(String resourceName)
return resourcePrinted;
}
- // ------------------------------------------------------------
- // implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy)
+ /* implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy) */
public void init(String[] args) throws Exception
{
try
@@ -674,22 +677,7 @@ public void init(String[] args) throws Exception
}
}
- // ------------------------------------------------------------
- // implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy)
- public void start() throws Exception
- {
- start(jsvcStartArgs);
- }
-
- // ------------------------------------------------------------
- // implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy)
- public void stop() throws Exception
- {
- doStop(jsvcStartArgs);
- }
-
- // ------------------------------------------------------------
- // implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy)
+ /* implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy) */
public void destroy()
{
}
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java
index 549878b14278..6bd794d1d7b4 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java
@@ -52,19 +52,19 @@ public static void debug(String format, Object... args)
}
}
- public static void trace(String format, Object... args)
+ public static void debug(Throwable t)
{
- if (INSTANCE.trace)
+ if (INSTANCE.debug)
{
- out.printf("TRACE " + format + "%n", args);
+ t.printStackTrace(out);
}
}
- public static void debug(Throwable t)
+ public static void trace(String format, Object... args)
{
- if (INSTANCE.debug)
+ if (INSTANCE.trace)
{
- t.printStackTrace(out);
+ out.printf("TRACE " + format + "%n", args);
}
}
@@ -88,14 +88,14 @@ public static void info(String format, Object... args)
log("INFO", format, args);
}
- public static void warn(String format, Object... args)
+ public static void error(String format, Object... args)
{
- log("WARN", format, args);
+ log("ERROR", format, args);
}
- public static void error(String format, Object... args)
+ public static void warn(String format, Object... args)
{
- log("ERROR", format, args);
+ log("WARN", format, args);
}
public static void warn(Throwable t)
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Version.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Version.java
index ad9dddec79c7..2bb08154816e 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/Version.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Version.java
@@ -252,6 +252,8 @@ else if (Character.isLetter(c))
update = val;
}
break;
+ default:
+ throw new IllegalStateException(state.toString());
}
offset++;
diff --git a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSON.java b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSON.java
index 93e5d8a7d1ce..18ebac7020c3 100644
--- a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSON.java
+++ b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSON.java
@@ -160,44 +160,9 @@ public static String toString(Object[] array)
return buffer.toString();
}
- /**
- * @param s String containing JSON object or array.
- * @return A Map, Object array or primitive array parsed from the JSON.
- */
- public static Object parse(String s)
- {
- return DEFAULT.parse(new StringSource(s), false);
- }
-
- /**
- * @param s String containing JSON object or array.
- * @param stripOuterComment If true, an outer comment around the JSON is ignored.
- * @return A Map, Object array or primitive array parsed from the JSON.
- */
- public static Object parse(String s, boolean stripOuterComment)
- {
- return DEFAULT.parse(new StringSource(s), stripOuterComment);
- }
-
- /**
- * @param in Reader containing JSON object or array.
- * @return A Map, Object array or primitive array parsed from the JSON.
- * @throws IOException if unable to parse
- */
- public static Object parse(Reader in) throws IOException
- {
- return DEFAULT.parse(new ReaderSource(in), false);
- }
-
- /**
- * @param in Reader containing JSON object or array.
- * @param stripOuterComment If true, an outer comment around the JSON is ignored.
- * @return A Map, Object array or primitive array parsed from the JSON.
- * @throws IOException if unable to parse
- */
- public static Object parse(Reader in, boolean stripOuterComment) throws IOException
+ protected String toString(char[] buffer, int offset, int length)
{
- return DEFAULT.parse(new ReaderSource(in), stripOuterComment);
+ return new String(buffer, offset, length);
}
private void quotedEscape(Appendable buffer, String input)
@@ -558,13 +523,6 @@ public void appendString(Appendable buffer, String string)
quotedEscape(buffer, string);
}
- // Parsing utilities
-
- protected String toString(char[] buffer, int offset, int length)
- {
- return new String(buffer, offset, length);
- }
-
protected Map newMap()
{
return new HashMap();
@@ -679,6 +637,46 @@ public Convertor getConvertorFor(String name)
return convertor;
}
+ /**
+ * @param in Reader containing JSON object or array.
+ * @param stripOuterComment If true, an outer comment around the JSON is ignored.
+ * @return A Map, Object array or primitive array parsed from the JSON.
+ * @throws IOException if unable to parse
+ */
+ public static Object parse(Reader in, boolean stripOuterComment) throws IOException
+ {
+ return DEFAULT.parse(new ReaderSource(in), stripOuterComment);
+ }
+
+ /**
+ * @param s String containing JSON object or array.
+ * @return A Map, Object array or primitive array parsed from the JSON.
+ */
+ public static Object parse(String s)
+ {
+ return DEFAULT.parse(new StringSource(s), false);
+ }
+
+ /**
+ * @param s String containing JSON object or array.
+ * @param stripOuterComment If true, an outer comment around the JSON is ignored.
+ * @return A Map, Object array or primitive array parsed from the JSON.
+ */
+ public static Object parse(String s, boolean stripOuterComment)
+ {
+ return DEFAULT.parse(new StringSource(s), stripOuterComment);
+ }
+
+ /**
+ * @param in Reader containing JSON object or array.
+ * @return A Map, Object array or primitive array parsed from the JSON.
+ * @throws IOException if unable to parse
+ */
+ public static Object parse(Reader in) throws IOException
+ {
+ return DEFAULT.parse(new ReaderSource(in), false);
+ }
+
public Object parse(Source source, boolean stripOuterComment)
{
int commentState = 0; // 0=no comment, 1="/", 2="/*", 3="/* *" -1="//"
@@ -707,6 +705,9 @@ public Object parse(Source source, boolean stripOuterComment)
commentState = 0;
stripState = 2;
}
+ break;
+ default:
+ break;
}
}
// handle /* C style */ comment
@@ -785,6 +786,9 @@ public Object parse(Source source)
break;
case '*':
commentState = 2;
+ break;
+ default:
+ break;
}
}
// handle /* C Style */ comment
@@ -1307,15 +1311,16 @@ public void add(Object obj)
}
@Override
- public void addClass(Class type)
+ public void add(String name, Object value)
{
try
{
if (c == 0)
throw new IllegalStateException();
_buffer.append(c);
- _buffer.append("\"class\":");
- append(_buffer, type.getName());
+ quotedEscape(_buffer, name);
+ _buffer.append(':');
+ append(_buffer, value);
c = ',';
}
catch (IOException e)
@@ -1325,7 +1330,7 @@ public void addClass(Class type)
}
@Override
- public void add(String name, Object value)
+ public void add(String name, double value)
{
try
{
@@ -1334,7 +1339,7 @@ public void add(String name, Object value)
_buffer.append(c);
quotedEscape(_buffer, name);
_buffer.append(':');
- append(_buffer, value);
+ appendNumber(_buffer, value);
c = ',';
}
catch (IOException e)
@@ -1344,7 +1349,7 @@ public void add(String name, Object value)
}
@Override
- public void add(String name, double value)
+ public void add(String name, long value)
{
try
{
@@ -1363,7 +1368,7 @@ public void add(String name, double value)
}
@Override
- public void add(String name, long value)
+ public void add(String name, boolean value)
{
try
{
@@ -1372,7 +1377,7 @@ public void add(String name, long value)
_buffer.append(c);
quotedEscape(_buffer, name);
_buffer.append(':');
- appendNumber(_buffer, value);
+ appendBoolean(_buffer, value ? Boolean.TRUE : Boolean.FALSE);
c = ',';
}
catch (IOException e)
@@ -1382,16 +1387,15 @@ public void add(String name, long value)
}
@Override
- public void add(String name, boolean value)
+ public void addClass(Class type)
{
try
{
if (c == 0)
throw new IllegalStateException();
_buffer.append(c);
- quotedEscape(_buffer, name);
- _buffer.append(':');
- appendBoolean(_buffer, value ? Boolean.TRUE : Boolean.FALSE);
+ _buffer.append("\"class\":");
+ append(_buffer, type.getName());
c = ',';
}
catch (IOException e)
diff --git a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java
index ab8361cfd0c5..6c2f41da55e2 100644
--- a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java
+++ b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java
@@ -119,7 +119,6 @@ protected void init()
switch (m.getParameterCount())
{
case 0:
-
if (m.getReturnType() != null)
{
if (name.startsWith("is") && name.length() > 2)
@@ -140,6 +139,9 @@ else if (name.startsWith("get") && name.length() > 3)
addSetter(name, m);
}
break;
+
+ default:
+ break;
}
}
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTernaryTrie.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTernaryTrie.java
index e4ca8a4bdbed..ac375695fd6c 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTernaryTrie.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTernaryTrie.java
@@ -572,12 +572,6 @@ public Growing(boolean insensitive, int capacity, int growby)
_trie = new ArrayTernaryTrie<>(insensitive, capacity);
}
- @Override
- public boolean put(V v)
- {
- return put(v.toString(), v);
- }
-
@Override
public int hashCode()
{
@@ -590,24 +584,6 @@ public V remove(String s)
return _trie.remove(s);
}
- @Override
- public V get(String s)
- {
- return _trie.get(s);
- }
-
- @Override
- public V get(ByteBuffer b)
- {
- return _trie.get(b);
- }
-
- @Override
- public V getBest(byte[] b, int offset, int len)
- {
- return _trie.getBest(b, offset, len);
- }
-
@Override
public boolean isCaseInsensitive()
{
@@ -626,6 +602,12 @@ public void clear()
_trie.clear();
}
+ @Override
+ public boolean put(V v)
+ {
+ return put(v.toString(), v);
+ }
+
@Override
public boolean put(String s, V v)
{
@@ -644,6 +626,18 @@ public boolean put(String s, V v)
return added;
}
+ @Override
+ public V get(String s)
+ {
+ return _trie.get(s);
+ }
+
+ @Override
+ public V get(ByteBuffer b)
+ {
+ return _trie.get(b);
+ }
+
@Override
public V get(String s, int offset, int len)
{
@@ -656,6 +650,12 @@ public V get(ByteBuffer b, int offset, int len)
return _trie.get(b, offset, len);
}
+ @Override
+ public V getBest(byte[] b, int offset, int len)
+ {
+ return _trie.getBest(b, offset, len);
+ }
+
@Override
public V getBest(String s)
{
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/AtomicBiInteger.java b/jetty-util/src/main/java/org/eclipse/jetty/util/AtomicBiInteger.java
index 290f1dae0fc4..3670349a0ab7 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/AtomicBiInteger.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/AtomicBiInteger.java
@@ -48,6 +48,17 @@ public int getHi()
return getHi(get());
}
+ /**
+ * Gets a hi value from the given encoded value.
+ *
+ * @param encoded the encoded value
+ * @return the hi value
+ */
+ public static int getHi(long encoded)
+ {
+ return (int)((encoded >> 32) & 0xFFFF_FFFFL);
+ }
+
/**
* @return the lo value
*/
@@ -56,6 +67,17 @@ public int getLo()
return getLo(get());
}
+ /**
+ * Gets a lo value from the given encoded value.
+ *
+ * @param encoded the encoded value
+ * @return the lo value
+ */
+ public static int getLo(long encoded)
+ {
+ return (int)(encoded & 0xFFFF_FFFFL);
+ }
+
/**
* Atomically sets the hi value without changing the lo value.
*
@@ -234,28 +256,6 @@ public void add(int deltaHi, int deltaLo)
}
}
- /**
- * Gets a hi value from the given encoded value.
- *
- * @param encoded the encoded value
- * @return the hi value
- */
- public static int getHi(long encoded)
- {
- return (int)((encoded >> 32) & 0xFFFF_FFFFL);
- }
-
- /**
- * Gets a lo value from the given encoded value.
- *
- * @param encoded the encoded value
- * @return the lo value
- */
- public static int getLo(long encoded)
- {
- return (int)(encoded & 0xFFFF_FFFFL);
- }
-
/**
* Encodes hi and lo values into a long.
*
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Atomics.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Atomics.java
index ffa1ace3cfd2..9589b79c808b 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/Atomics.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Atomics.java
@@ -39,26 +39,26 @@ public static boolean updateMin(AtomicLong currentMin, long newValue)
return false;
}
- public static boolean updateMax(AtomicLong currentMax, long newValue)
+ public static boolean updateMin(AtomicInteger currentMin, int newValue)
{
- long oldValue = currentMax.get();
- while (newValue > oldValue)
+ int oldValue = currentMin.get();
+ while (newValue < oldValue)
{
- if (currentMax.compareAndSet(oldValue, newValue))
+ if (currentMin.compareAndSet(oldValue, newValue))
return true;
- oldValue = currentMax.get();
+ oldValue = currentMin.get();
}
return false;
}
- public static boolean updateMin(AtomicInteger currentMin, int newValue)
+ public static boolean updateMax(AtomicLong currentMax, long newValue)
{
- int oldValue = currentMin.get();
- while (newValue < oldValue)
+ long oldValue = currentMax.get();
+ while (newValue > oldValue)
{
- if (currentMin.compareAndSet(oldValue, newValue))
+ if (currentMax.compareAndSet(oldValue, newValue))
return true;
- oldValue = currentMin.get();
+ oldValue = currentMax.get();
}
return false;
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/BlockingArrayQueue.java b/jetty-util/src/main/java/org/eclipse/jetty/util/BlockingArrayQueue.java
index a47b500157c3..0de21d962a7a 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/BlockingArrayQueue.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/BlockingArrayQueue.java
@@ -205,6 +205,46 @@ public E poll()
return e;
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public E poll(long time, TimeUnit unit) throws InterruptedException
+ {
+ long nanos = unit.toNanos(time);
+ E e = null;
+
+ _headLock.lockInterruptibly(); // Size cannot shrink
+ try
+ {
+ try
+ {
+ while (_size.get() == 0)
+ {
+ if (nanos <= 0)
+ return null;
+ nanos = _notEmpty.awaitNanos(nanos);
+ }
+ }
+ catch (InterruptedException x)
+ {
+ _notEmpty.signal();
+ throw x;
+ }
+
+ int head = _indexes[HEAD_OFFSET];
+ e = (E)_elements[head];
+ _elements[head] = null;
+ _indexes[HEAD_OFFSET] = (head + 1) % _elements.length;
+
+ if (_size.decrementAndGet() > 0)
+ _notEmpty.signal();
+ }
+ finally
+ {
+ _headLock.unlock();
+ }
+ return e;
+ }
+
@SuppressWarnings("unchecked")
@Override
public E peek()
@@ -236,6 +276,108 @@ public E remove()
return e;
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public E remove(int index)
+ {
+
+ _tailLock.lock();
+ try
+ {
+
+ _headLock.lock();
+ try
+ {
+ if (index < 0 || index >= _size.get())
+ throw new IndexOutOfBoundsException("!(" + 0 + "<" + index + "<=" + _size + ")");
+
+ int i = _indexes[HEAD_OFFSET] + index;
+ int capacity = _elements.length;
+ if (i >= capacity)
+ i -= capacity;
+ E old = (E)_elements[i];
+
+ int tail = _indexes[TAIL_OFFSET];
+ if (i < tail)
+ {
+ System.arraycopy(_elements, i + 1, _elements, i, tail - i);
+ --_indexes[TAIL_OFFSET];
+ }
+ else
+ {
+ System.arraycopy(_elements, i + 1, _elements, i, capacity - i - 1);
+ _elements[capacity - 1] = _elements[0];
+ if (tail > 0)
+ {
+ System.arraycopy(_elements, 1, _elements, 0, tail);
+ --_indexes[TAIL_OFFSET];
+ }
+ else
+ {
+ _indexes[TAIL_OFFSET] = capacity - 1;
+ }
+ _elements[_indexes[TAIL_OFFSET]] = null;
+ }
+
+ _size.decrementAndGet();
+
+ return old;
+ }
+ finally
+ {
+ _headLock.unlock();
+ }
+ }
+ finally
+ {
+ _tailLock.unlock();
+ }
+ }
+
+ @Override
+ public boolean remove(Object o)
+ {
+
+ _tailLock.lock();
+ try
+ {
+
+ _headLock.lock();
+ try
+ {
+ if (isEmpty())
+ return false;
+
+ final int head = _indexes[HEAD_OFFSET];
+ final int tail = _indexes[TAIL_OFFSET];
+ final int capacity = _elements.length;
+
+ int i = head;
+ while (true)
+ {
+ if (Objects.equals(_elements[i], o))
+ {
+ remove(i >= head ? i - head : capacity - head + i);
+ return true;
+ }
+ ++i;
+ if (i == capacity)
+ i = 0;
+ if (i == tail)
+ return false;
+ }
+ }
+ finally
+ {
+ _headLock.unlock();
+ }
+ }
+ finally
+ {
+ _tailLock.unlock();
+ }
+ }
+
@Override
public E element()
{
@@ -304,70 +446,100 @@ public boolean offer(E e)
}
@Override
- public boolean add(E e)
- {
- if (offer(e))
- return true;
- else
- throw new IllegalStateException();
- }
-
- @Override
- public void put(E o) throws InterruptedException
+ public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException
{
// The mechanism to await and signal when the queue is full is not implemented
throw new UnsupportedOperationException();
}
@Override
- public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException
+ public boolean add(E e)
{
- // The mechanism to await and signal when the queue is full is not implemented
- throw new UnsupportedOperationException();
+ if (offer(e))
+ return true;
+ else
+ throw new IllegalStateException();
}
- @SuppressWarnings("unchecked")
@Override
- public E take() throws InterruptedException
+ public void add(int index, E e)
{
- E e = null;
+ if (e == null)
+ throw new NullPointerException();
- _headLock.lockInterruptibly(); // Size cannot shrink
+ _tailLock.lock();
try
{
+
+ _headLock.lock();
try
{
- while (_size.get() == 0)
+ final int size = _size.get();
+
+ if (index < 0 || index > size)
+ throw new IndexOutOfBoundsException("!(" + 0 + "<" + index + "<=" + _size + ")");
+
+ if (index == size)
{
- _notEmpty.await();
+ add(e);
+ }
+ else
+ {
+ if (_indexes[TAIL_OFFSET] == _indexes[HEAD_OFFSET])
+ if (!grow())
+ throw new IllegalStateException("full");
+
+ // Re-read head and tail after a possible grow
+ int i = _indexes[HEAD_OFFSET] + index;
+ int capacity = _elements.length;
+
+ if (i >= capacity)
+ i -= capacity;
+
+ _size.incrementAndGet();
+ int tail = _indexes[TAIL_OFFSET];
+ _indexes[TAIL_OFFSET] = tail = (tail + 1) % capacity;
+
+ if (i < tail)
+ {
+ System.arraycopy(_elements, i, _elements, i + 1, tail - i);
+ _elements[i] = e;
+ }
+ else
+ {
+ if (tail > 0)
+ {
+ System.arraycopy(_elements, 0, _elements, 1, tail);
+ _elements[0] = _elements[capacity - 1];
+ }
+
+ System.arraycopy(_elements, i, _elements, i + 1, capacity - i - 1);
+ _elements[i] = e;
+ }
}
}
- catch (InterruptedException ex)
+ finally
{
- _notEmpty.signal();
- throw ex;
+ _headLock.unlock();
}
-
- final int head = _indexes[HEAD_OFFSET];
- e = (E)_elements[head];
- _elements[head] = null;
- _indexes[HEAD_OFFSET] = (head + 1) % _elements.length;
-
- if (_size.decrementAndGet() > 0)
- _notEmpty.signal();
}
finally
{
- _headLock.unlock();
+ _tailLock.unlock();
}
- return e;
+ }
+
+ @Override
+ public void put(E o) throws InterruptedException
+ {
+ // The mechanism to await and signal when the queue is full is not implemented
+ throw new UnsupportedOperationException();
}
@SuppressWarnings("unchecked")
@Override
- public E poll(long time, TimeUnit unit) throws InterruptedException
+ public E take() throws InterruptedException
{
- long nanos = unit.toNanos(time);
E e = null;
_headLock.lockInterruptibly(); // Size cannot shrink
@@ -377,18 +549,16 @@ public E poll(long time, TimeUnit unit) throws InterruptedException
{
while (_size.get() == 0)
{
- if (nanos <= 0)
- return null;
- nanos = _notEmpty.awaitNanos(nanos);
+ _notEmpty.await();
}
}
- catch (InterruptedException x)
+ catch (InterruptedException ex)
{
_notEmpty.signal();
- throw x;
+ throw ex;
}
- int head = _indexes[HEAD_OFFSET];
+ final int head = _indexes[HEAD_OFFSET];
e = (E)_elements[head];
_elements[head] = null;
_indexes[HEAD_OFFSET] = (head + 1) % _elements.length;
@@ -403,50 +573,6 @@ public E poll(long time, TimeUnit unit) throws InterruptedException
return e;
}
- @Override
- public boolean remove(Object o)
- {
-
- _tailLock.lock();
- try
- {
-
- _headLock.lock();
- try
- {
- if (isEmpty())
- return false;
-
- final int head = _indexes[HEAD_OFFSET];
- final int tail = _indexes[TAIL_OFFSET];
- final int capacity = _elements.length;
-
- int i = head;
- while (true)
- {
- if (Objects.equals(_elements[i], o))
- {
- remove(i >= head ? i - head : capacity - head + i);
- return true;
- }
- ++i;
- if (i == capacity)
- i = 0;
- if (i == tail)
- return false;
- }
- }
- finally
- {
- _headLock.unlock();
- }
- }
- finally
- {
- _tailLock.unlock();
- }
- }
-
@Override
public int remainingCapacity()
{
@@ -558,74 +684,6 @@ public E get(int index)
}
}
- @Override
- public void add(int index, E e)
- {
- if (e == null)
- throw new NullPointerException();
-
- _tailLock.lock();
- try
- {
-
- _headLock.lock();
- try
- {
- final int size = _size.get();
-
- if (index < 0 || index > size)
- throw new IndexOutOfBoundsException("!(" + 0 + "<" + index + "<=" + _size + ")");
-
- if (index == size)
- {
- add(e);
- }
- else
- {
- if (_indexes[TAIL_OFFSET] == _indexes[HEAD_OFFSET])
- if (!grow())
- throw new IllegalStateException("full");
-
- // Re-read head and tail after a possible grow
- int i = _indexes[HEAD_OFFSET] + index;
- int capacity = _elements.length;
-
- if (i >= capacity)
- i -= capacity;
-
- _size.incrementAndGet();
- int tail = _indexes[TAIL_OFFSET];
- _indexes[TAIL_OFFSET] = tail = (tail + 1) % capacity;
-
- if (i < tail)
- {
- System.arraycopy(_elements, i, _elements, i + 1, tail - i);
- _elements[i] = e;
- }
- else
- {
- if (tail > 0)
- {
- System.arraycopy(_elements, 0, _elements, 1, tail);
- _elements[0] = _elements[capacity - 1];
- }
-
- System.arraycopy(_elements, i, _elements, i + 1, capacity - i - 1);
- _elements[i] = e;
- }
- }
- }
- finally
- {
- _headLock.unlock();
- }
- }
- finally
- {
- _tailLock.unlock();
- }
- }
-
@SuppressWarnings("unchecked")
@Override
public E set(int index, E e)
@@ -661,64 +719,6 @@ public E set(int index, E e)
}
}
- @SuppressWarnings("unchecked")
- @Override
- public E remove(int index)
- {
-
- _tailLock.lock();
- try
- {
-
- _headLock.lock();
- try
- {
- if (index < 0 || index >= _size.get())
- throw new IndexOutOfBoundsException("!(" + 0 + "<" + index + "<=" + _size + ")");
-
- int i = _indexes[HEAD_OFFSET] + index;
- int capacity = _elements.length;
- if (i >= capacity)
- i -= capacity;
- E old = (E)_elements[i];
-
- int tail = _indexes[TAIL_OFFSET];
- if (i < tail)
- {
- System.arraycopy(_elements, i + 1, _elements, i, tail - i);
- --_indexes[TAIL_OFFSET];
- }
- else
- {
- System.arraycopy(_elements, i + 1, _elements, i, capacity - i - 1);
- _elements[capacity - 1] = _elements[0];
- if (tail > 0)
- {
- System.arraycopy(_elements, 1, _elements, 0, tail);
- --_indexes[TAIL_OFFSET];
- }
- else
- {
- _indexes[TAIL_OFFSET] = capacity - 1;
- }
- _elements[_indexes[TAIL_OFFSET]] = null;
- }
-
- _size.decrementAndGet();
-
- return old;
- }
- finally
- {
- _headLock.unlock();
- }
- }
- finally
- {
- _tailLock.unlock();
- }
- }
-
@Override
public ListIterator listIterator(int index)
{
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java
index c91ffe85e916..2c87eb72f6b8 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java
@@ -97,11 +97,11 @@ public class BufferUtil
static final byte SPACE = 0x20;
static final byte MINUS = '-';
static final byte[] DIGIT =
- {
- (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9',
- (byte)'A', (byte)'B', (byte)'C', (byte)'D',
- (byte)'E', (byte)'F'
- };
+ {
+ (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9',
+ (byte)'A', (byte)'B', (byte)'C', (byte)'D',
+ (byte)'E', (byte)'F'
+ };
public static final ByteBuffer EMPTY_BUFFER = ByteBuffer.wrap(new byte[0]);
@@ -589,17 +589,6 @@ public static String toString(ByteBuffer buffer)
return toString(buffer, StandardCharsets.ISO_8859_1);
}
- /**
- * Convert the buffer to an UTF-8 String
- *
- * @param buffer The buffer to convert in flush mode. The buffer is unchanged
- * @return The buffer as a string.
- */
- public static String toUTF8String(ByteBuffer buffer)
- {
- return toString(buffer, StandardCharsets.UTF_8);
- }
-
/**
* Convert the buffer to an ISO-8859-1 String
*
@@ -647,6 +636,17 @@ public static String toString(ByteBuffer buffer, int position, int length, Chars
return new String(array, buffer.arrayOffset() + position, length, charset);
}
+ /**
+ * Convert the buffer to an UTF-8 String
+ *
+ * @param buffer The buffer to convert in flush mode. The buffer is unchanged
+ * @return The buffer as a string.
+ */
+ public static String toUTF8String(ByteBuffer buffer)
+ {
+ return toString(buffer, StandardCharsets.UTF_8);
+ }
+
/**
* Convert buffer to an integer. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown
*
@@ -964,6 +964,29 @@ public static ByteBuffer toBuffer(byte[] array, int offset, int length)
return ByteBuffer.wrap(array, offset, length);
}
+ public static ByteBuffer toBuffer(Resource resource, boolean direct) throws IOException
+ {
+ int len = (int)resource.length();
+ if (len < 0)
+ throw new IllegalArgumentException("invalid resource: " + String.valueOf(resource) + " len=" + len);
+
+ ByteBuffer buffer = direct ? BufferUtil.allocateDirect(len) : BufferUtil.allocate(len);
+
+ int pos = BufferUtil.flipToFill(buffer);
+ if (resource.getFile() != null)
+ BufferUtil.readFrom(resource.getFile(), buffer);
+ else
+ {
+ try (InputStream is = resource.getInputStream();)
+ {
+ BufferUtil.readFrom(is, len, buffer);
+ }
+ }
+ BufferUtil.flipToFlush(buffer, pos);
+
+ return buffer;
+ }
+
public static ByteBuffer toDirectBuffer(String s)
{
return toDirectBuffer(s, StandardCharsets.ISO_8859_1);
@@ -988,29 +1011,6 @@ public static ByteBuffer toMappedBuffer(File file) throws IOException
}
}
- public static ByteBuffer toBuffer(Resource resource, boolean direct) throws IOException
- {
- int len = (int)resource.length();
- if (len < 0)
- throw new IllegalArgumentException("invalid resource: " + String.valueOf(resource) + " len=" + len);
-
- ByteBuffer buffer = direct ? BufferUtil.allocateDirect(len) : BufferUtil.allocate(len);
-
- int pos = BufferUtil.flipToFill(buffer);
- if (resource.getFile() != null)
- BufferUtil.readFrom(resource.getFile(), buffer);
- else
- {
- try (InputStream is = resource.getInputStream();)
- {
- BufferUtil.readFrom(is, len, buffer);
- }
- }
- BufferUtil.flipToFlush(buffer, pos);
-
- return buffer;
- }
-
public static String toSummaryString(ByteBuffer buffer)
{
if (buffer == null)
@@ -1042,6 +1042,36 @@ public static String toDetailString(ByteBuffer[] buffer)
return builder.toString();
}
+ /**
+ * Convert Buffer to a detail debug string of pointers and content
+ *
+ * @param buffer the buffer to generate a detail string from
+ * @return A string showing the pointers and content of the buffer
+ */
+ public static String toDetailString(ByteBuffer buffer)
+ {
+ if (buffer == null)
+ return "null";
+
+ StringBuilder buf = new StringBuilder();
+ idString(buffer, buf);
+ buf.append("[p=");
+ buf.append(buffer.position());
+ buf.append(",l=");
+ buf.append(buffer.limit());
+ buf.append(",c=");
+ buf.append(buffer.capacity());
+ buf.append(",r=");
+ buf.append(buffer.remaining());
+ buf.append("]={");
+
+ appendDebugString(buf, buffer);
+
+ buf.append("}");
+
+ return buf.toString();
+ }
+
/**
* Convert Buffer to string ID independent of content
*/
@@ -1075,36 +1105,6 @@ public static String toIDString(ByteBuffer buffer)
return buf.toString();
}
- /**
- * Convert Buffer to a detail debug string of pointers and content
- *
- * @param buffer the buffer to generate a detail string from
- * @return A string showing the pointers and content of the buffer
- */
- public static String toDetailString(ByteBuffer buffer)
- {
- if (buffer == null)
- return "null";
-
- StringBuilder buf = new StringBuilder();
- idString(buffer, buf);
- buf.append("[p=");
- buf.append(buffer.position());
- buf.append(",l=");
- buf.append(buffer.limit());
- buf.append(",c=");
- buf.append(buffer.capacity());
- buf.append(",r=");
- buf.append(buffer.remaining());
- buf.append("]={");
-
- appendDebugString(buf, buffer);
-
- buf.append("}");
-
- return buf.toString();
- }
-
private static void appendDebugString(StringBuilder buf, ByteBuffer buffer)
{
// Take a readonly copy so we can adjust the limit
@@ -1206,17 +1206,21 @@ public static String toHexString(ByteBuffer buffer)
}
private static final int[] decDivisors =
- {1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1};
+ {
+ 1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1
+ };
private static final int[] hexDivisors =
- {0x10000000, 0x1000000, 0x100000, 0x10000, 0x1000, 0x100, 0x10, 0x1};
+ {
+ 0x10000000, 0x1000000, 0x100000, 0x10000, 0x1000, 0x100, 0x10, 0x1
+ };
private static final long[] decDivisorsL =
- {
- 1000000000000000000L, 100000000000000000L, 10000000000000000L, 1000000000000000L, 100000000000000L, 10000000000000L,
- 1000000000000L, 100000000000L,
- 10000000000L, 1000000000L, 100000000L, 10000000L, 1000000L, 100000L, 10000L, 1000L, 100L, 10L, 1L
- };
+ {
+ 1000000000000000000L, 100000000000000000L, 10000000000000000L, 1000000000000000L, 100000000000000L, 10000000000000L,
+ 1000000000000L, 100000000000L,
+ 10000000000L, 1000000000L, 100000000L, 10000000L, 1000000L, 100000L, 10000L, 1000L, 100L, 10L, 1L
+ };
public static void putCRLF(ByteBuffer buffer)
{
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
index b036a75abb84..e50799fa12f4 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
@@ -269,7 +269,6 @@ public void failed(Throwable x)
};
}
-
class Completing implements Callback
{
@Override
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/DateCache.java b/jetty-util/src/main/java/org/eclipse/jetty/util/DateCache.java
index 9ef616b617bc..7d2b1d66cec9 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/DateCache.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/DateCache.java
@@ -104,8 +104,8 @@ public DateCache(String format, Locale l, TimeZone tz)
int zIndex = _formatString.indexOf("ZZZ");
if (zIndex >= 0)
{
- String ss1 = _formatString.substring(0, zIndex);
- String ss2 = _formatString.substring(zIndex + 3);
+ final String ss1 = _formatString.substring(0, zIndex);
+ final String ss2 = _formatString.substring(zIndex + 3);
int tzOffset = tz.getRawOffset();
StringBuilder sb = new StringBuilder(_formatString.length() + 10);
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartWriter.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartWriter.java
index d029c14e57e2..160671734122 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartWriter.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartWriter.java
@@ -99,19 +99,6 @@ public void startPart(String contentType)
inPart = true;
}
- /**
- * end creation of the next Content.
- *
- * @throws IOException if unable to write the part
- */
- public void endPart()
- throws IOException
- {
- if (inPart)
- out.write(__CRLF);
- inPart = false;
- }
-
/**
* Start creation of the next Content.
*
@@ -138,6 +125,19 @@ public void startPart(String contentType, String[] headers)
out.write(__CRLF);
inPart = true;
}
+
+ /**
+ * end creation of the next Content.
+ *
+ * @throws IOException if unable to write the part
+ */
+ public void endPart()
+ throws IOException
+ {
+ if (inPart)
+ out.write(__CRLF);
+ inPart = false;
+ }
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/PathWatcher.java b/jetty-util/src/main/java/org/eclipse/jetty/util/PathWatcher.java
index d824bfbc10ce..9a7a21678901 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/PathWatcher.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/PathWatcher.java
@@ -1276,6 +1276,9 @@ public void handleWatchEvent(Path path, PathWatchEvent event)
pending.remove(path);
events.add(event);
break;
+
+ default:
+ throw new IllegalStateException(event.toString());
}
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/QuotedStringTokenizer.java b/jetty-util/src/main/java/org/eclipse/jetty/util/QuotedStringTokenizer.java
index 3abfff1bc1de..da2d3da67e5c 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/QuotedStringTokenizer.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/QuotedStringTokenizer.java
@@ -207,6 +207,9 @@ else if (c == '\\')
_token.append(c);
}
break;
+
+ default:
+ throw new IllegalStateException();
}
}
@@ -358,12 +361,12 @@ public static String quote(String s)
/**
* Quote a string into an Appendable.
- * Only quotes and backslash are escaped.
+ * The characters ", \, \n, \r, \t, \f and \b are escaped
*
* @param buffer The Appendable
* @param input The String to quote.
*/
- public static void quoteOnly(Appendable buffer, String input)
+ public static void quote(Appendable buffer, String input)
{
if (input == null)
return;
@@ -374,9 +377,28 @@ public static void quoteOnly(Appendable buffer, String input)
for (int i = 0; i < input.length(); ++i)
{
char c = input.charAt(i);
- if (c == '"' || c == '\\')
- buffer.append('\\');
- buffer.append(c);
+ if (c >= 32)
+ {
+ if (c == '"' || c == '\\')
+ buffer.append('\\');
+ buffer.append(c);
+ }
+ else
+ {
+ char escape = escapes[c];
+ if (escape == 0xFFFF)
+ {
+ // Unicode escape
+ buffer.append('\\').append('u').append('0').append('0');
+ if (c < 0x10)
+ buffer.append('0');
+ buffer.append(Integer.toString(c, 16));
+ }
+ else
+ {
+ buffer.append('\\').append(escape);
+ }
+ }
}
buffer.append('"');
}
@@ -388,12 +410,12 @@ public static void quoteOnly(Appendable buffer, String input)
/**
* Quote a string into an Appendable.
- * The characters ", \, \n, \r, \t, \f and \b are escaped
+ * Only quotes and backslash are escaped.
*
* @param buffer The Appendable
* @param input The String to quote.
*/
- public static void quote(Appendable buffer, String input)
+ public static void quoteOnly(Appendable buffer, String input)
{
if (input == null)
return;
@@ -404,28 +426,9 @@ public static void quote(Appendable buffer, String input)
for (int i = 0; i < input.length(); ++i)
{
char c = input.charAt(i);
- if (c >= 32)
- {
- if (c == '"' || c == '\\')
- buffer.append('\\');
- buffer.append(c);
- }
- else
- {
- char escape = escapes[c];
- if (escape == 0xFFFF)
- {
- // Unicode escape
- buffer.append('\\').append('u').append('0').append('0');
- if (c < 0x10)
- buffer.append('0');
- buffer.append(Integer.toString(c, 16));
- }
- else
- {
- buffer.append('\\').append(escape);
- }
- }
+ if (c == '"' || c == '\\')
+ buffer.append('\\');
+ buffer.append(c);
}
buffer.append('"');
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java
index a3a7d0961299..81e94d01d379 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java
@@ -475,6 +475,9 @@ public synchronized void reportDifferences(Map currentScan, M
case REMOVED:
case CHANGED:
_notifications.put(file, Notification.CHANGED);
+ break;
+ default:
+ break;
}
}
}
@@ -487,6 +490,9 @@ else if (!oldScan.get(file).equals(currentScan.get(file)))
{
case ADDED:
_notifications.put(file, Notification.ADDED);
+ break;
+ default:
+ break;
}
}
}
@@ -504,6 +510,9 @@ else if (!oldScan.get(file).equals(currentScan.get(file)))
{
case ADDED:
_notifications.remove(file);
+ break;
+ default:
+ break;
}
}
}
@@ -544,6 +553,8 @@ else if (currentScan.containsKey(file))
case REMOVED:
reportRemoval(file);
break;
+ default:
+ break;
}
}
if (!bulkChanges.isEmpty())
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/StringUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/StringUtil.java
index 7bba48705e73..51ec5e98d61b 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/StringUtil.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/StringUtil.java
@@ -88,24 +88,24 @@ public static String normalizeCharset(String s, int offset, int length)
// @checkstyle-disable-check : IllegalTokenTextCheck
public static final char[] lowercases =
- {
- '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
- '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
- '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
- '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
- '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
- '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
- '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
- '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
- '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
- '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177'
- };
+ {
+ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
+ '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
+ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
+ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
+ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
+ '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
+ '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
+ '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
+ '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+ '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
+ '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+ '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177'
+ };
// @checkstyle-enable-check : IllegalTokenTextCheck
@@ -671,11 +671,6 @@ public static byte[] getBytes(String s)
return s.getBytes(StandardCharsets.ISO_8859_1);
}
- public static byte[] getUtf8Bytes(String s)
- {
- return s.getBytes(StandardCharsets.UTF_8);
- }
-
public static byte[] getBytes(String s, String charset)
{
try
@@ -689,6 +684,11 @@ public static byte[] getBytes(String s, String charset)
}
}
+ public static byte[] getUtf8Bytes(String s)
+ {
+ return s.getBytes(StandardCharsets.UTF_8);
+ }
+
/**
* Convert String to an integer. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown
*
@@ -883,6 +883,7 @@ public static List csvSplit(List list, String s, int off, int le
state = CsvSplitState.DATA;
out.append(ch);
continue;
+
case DATA:
if (Character.isWhitespace(ch))
{
@@ -922,6 +923,7 @@ public static List csvSplit(List list, String s, int off, int le
out.append(ch);
last = -1;
continue;
+
case QUOTE:
if ('\\' == ch)
{
@@ -950,6 +952,9 @@ public static List csvSplit(List list, String s, int off, int le
continue;
}
continue;
+
+ default:
+ throw new IllegalStateException(state.toString());
}
}
switch (state)
@@ -957,6 +962,7 @@ public static List csvSplit(List list, String s, int off, int le
case PRE_DATA:
case POST_DATA:
break;
+
case DATA:
case QUOTE:
case SLOSH:
@@ -967,6 +973,9 @@ public static List csvSplit(List list, String s, int off, int le
out.setLength(last);
list.add(out.toString());
break;
+
+ default:
+ throw new IllegalStateException(state.toString());
}
return list;
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java
index bd40716fdcfb..738c3879afc0 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java
@@ -622,14 +622,14 @@ public static URI getLocationOfClass(Class> clazz)
return null;
}
- public static URI getClassLoaderLocation(Class> clazz)
+ public static URI getSystemClassLoaderLocation(Class> clazz)
{
- return getClassLoaderLocation(clazz, clazz.getClassLoader());
+ return getClassLoaderLocation(clazz, ClassLoader.getSystemClassLoader());
}
- public static URI getSystemClassLoaderLocation(Class> clazz)
+ public static URI getClassLoaderLocation(Class> clazz)
{
- return getClassLoaderLocation(clazz, ClassLoader.getSystemClassLoader());
+ return getClassLoaderLocation(clazz, clazz.getClassLoader());
}
public static URI getClassLoaderLocation(Class> clazz, ClassLoader loader)
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Uptime.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Uptime.java
index 2c925769ab1d..ed1b19656fff 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/Uptime.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Uptime.java
@@ -43,10 +43,10 @@ public DefaultImpl()
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try
{
- Class> mgmtFactory = Class.forName("java.lang.management.ManagementFactory", true, cl);
- Class> runtimeClass = Class.forName("java.lang.management.RuntimeMXBean", true, cl);
- Class>[] noParams = new Class>[0];
- Method mxBeanMethod = mgmtFactory.getMethod("getRuntimeMXBean", noParams);
+ final Class> mgmtFactory = Class.forName("java.lang.management.ManagementFactory", true, cl);
+ final Class> runtimeClass = Class.forName("java.lang.management.RuntimeMXBean", true, cl);
+ final Class>[] noParams = new Class>[0];
+ final Method mxBeanMethod = mgmtFactory.getMethod("getRuntimeMXBean", noParams);
if (mxBeanMethod == null)
{
throw new UnsupportedOperationException("method getRuntimeMXBean() not found");
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java
index 3e31f12d38fd..ab6877d58d1b 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java
@@ -269,6 +269,8 @@ else if (value != null && value.length() > 0)
case '%':
encoded = true;
break;
+ default:
+ break;
}
}
@@ -291,6 +293,146 @@ else if (mark < content.length())
}
}
+ /**
+ * Decoded parameters to Map.
+ *
+ * @param in the stream containing the encoded parameters
+ * @param map the MultiMap to decode into
+ * @param charset the charset to use for decoding
+ * @param maxLength the maximum length of the form to decode
+ * @param maxKeys the maximum number of keys to decode
+ * @throws IOException if unable to decode input stream
+ */
+ public static void decodeTo(InputStream in, MultiMap map, String charset, int maxLength, int maxKeys)
+ throws IOException
+ {
+ if (charset == null)
+ {
+ if (ENCODING.equals(StandardCharsets.UTF_8))
+ decodeUtf8To(in, map, maxLength, maxKeys);
+ else
+ decodeTo(in, map, ENCODING, maxLength, maxKeys);
+ }
+ else if (StringUtil.__UTF8.equalsIgnoreCase(charset))
+ decodeUtf8To(in, map, maxLength, maxKeys);
+ else if (StringUtil.__ISO_8859_1.equalsIgnoreCase(charset))
+ decode88591To(in, map, maxLength, maxKeys);
+ else if (StringUtil.__UTF16.equalsIgnoreCase(charset))
+ decodeUtf16To(in, map, maxLength, maxKeys);
+ else
+ decodeTo(in, map, Charset.forName(charset), maxLength, maxKeys);
+ }
+
+ /**
+ * Decoded parameters to Map.
+ *
+ * @param in the stream containing the encoded parameters
+ * @param map the MultiMap to decode into
+ * @param charset the charset to use for decoding
+ * @param maxLength the maximum length of the form to decode
+ * @param maxKeys the maximum number of keys to decode
+ * @throws IOException if unable to decode input stream
+ */
+ public static void decodeTo(InputStream in, MultiMap map, Charset charset, int maxLength, int maxKeys)
+ throws IOException
+ {
+ //no charset present, use the configured default
+ if (charset == null)
+ charset = ENCODING;
+
+ if (StandardCharsets.UTF_8.equals(charset))
+ {
+ decodeUtf8To(in, map, maxLength, maxKeys);
+ return;
+ }
+
+ if (StandardCharsets.ISO_8859_1.equals(charset))
+ {
+ decode88591To(in, map, maxLength, maxKeys);
+ return;
+ }
+
+ if (StandardCharsets.UTF_16.equals(charset)) // Should be all 2 byte encodings
+ {
+ decodeUtf16To(in, map, maxLength, maxKeys);
+ return;
+ }
+
+ synchronized (map)
+ {
+ String key = null;
+ String value = null;
+
+ int c;
+
+ int totalLength = 0;
+
+ try (ByteArrayOutputStream2 output = new ByteArrayOutputStream2();)
+ {
+ int size = 0;
+
+ while ((c = in.read()) > 0)
+ {
+ switch ((char)c)
+ {
+ case '&':
+ size = output.size();
+ value = size == 0 ? "" : output.toString(charset);
+ output.setCount(0);
+ if (key != null)
+ {
+ map.add(key, value);
+ }
+ else if (value != null && value.length() > 0)
+ {
+ map.add(value, "");
+ }
+ key = null;
+ value = null;
+ if (maxKeys > 0 && map.size() > maxKeys)
+ throw new IllegalStateException(String.format("Form with too many keys [%d > %d]", map.size(), maxKeys));
+ break;
+ case '=':
+ if (key != null)
+ {
+ output.write(c);
+ break;
+ }
+ size = output.size();
+ key = size == 0 ? "" : output.toString(charset);
+ output.setCount(0);
+ break;
+ case '+':
+ output.write(' ');
+ break;
+ case '%':
+ int code0 = in.read();
+ int code1 = in.read();
+ output.write(decodeHexChar(code0, code1));
+ break;
+ default:
+ output.write(c);
+ break;
+ }
+
+ totalLength++;
+ if (maxLength >= 0 && totalLength > maxLength)
+ throw new IllegalStateException("Form is too large");
+ }
+
+ size = output.size();
+ if (key != null)
+ {
+ value = size == 0 ? "" : output.toString(charset);
+ output.setCount(0);
+ map.add(key, value);
+ }
+ else if (size > 0)
+ map.add(output.toString(charset), "");
+ }
+ }
+ }
+
public static void decodeUtf8To(String query, MultiMap map)
{
decodeUtf8To(query, 0, query.length(), map);
@@ -380,20 +522,20 @@ else if (buffer.length() > 0)
}
/**
- * Decoded parameters to MultiMap, using ISO8859-1 encodings.
+ * Decoded parameters to Map.
*
* @param in InputSteam to read
* @param map MultiMap to add parameters to
- * @param maxLength maximum length of form to read
- * @param maxKeys maximum number of keys to read or -1 for no limit
- * @throws IOException if unable to decode inputstream as ISO8859-1
+ * @param maxLength maximum form length to decode
+ * @param maxKeys the maximum number of keys to read or -1 for no limit
+ * @throws IOException if unable to decode input stream
*/
- public static void decode88591To(InputStream in, MultiMap map, int maxLength, int maxKeys)
+ public static void decodeUtf8To(InputStream in, MultiMap map, int maxLength, int maxKeys)
throws IOException
{
synchronized (map)
{
- StringBuffer buffer = new StringBuffer();
+ Utf8StringBuilder buffer = new Utf8StringBuilder();
String key = null;
String value = null;
@@ -405,8 +547,8 @@ public static void decode88591To(InputStream in, MultiMap map, int maxLe
switch ((char)b)
{
case '&':
- value = buffer.length() == 0 ? "" : buffer.toString();
- buffer.setLength(0);
+ value = buffer.toReplacedString();
+ buffer.reset();
if (key != null)
{
map.add(key, value);
@@ -424,59 +566,69 @@ else if (value != null && value.length() > 0)
case '=':
if (key != null)
{
- buffer.append((char)b);
+ buffer.append((byte)b);
break;
}
- key = buffer.toString();
- buffer.setLength(0);
+ key = buffer.toReplacedString();
+ buffer.reset();
break;
case '+':
- buffer.append(' ');
+ buffer.append((byte)' ');
break;
case '%':
- int code0 = in.read();
- int code1 = in.read();
- buffer.append(decodeHexChar(code0, code1));
+ char code0 = (char)in.read();
+ char code1 = (char)in.read();
+ buffer.append(decodeHexByte(code0, code1));
break;
default:
- buffer.append((char)b);
+ buffer.append((byte)b);
break;
}
if (maxLength >= 0 && (++totalLength > maxLength))
- throw new IllegalStateException(String.format("Form with too many keys [%d > %d]", map.size(), maxKeys));
+ throw new IllegalStateException("Form is too large");
}
if (key != null)
{
- value = buffer.length() == 0 ? "" : buffer.toString();
- buffer.setLength(0);
+ value = buffer.toReplacedString();
+ buffer.reset();
map.add(key, value);
}
else if (buffer.length() > 0)
{
- map.add(buffer.toString(), "");
+ map.add(buffer.toReplacedString(), "");
}
}
}
+ public static void decodeUtf16To(InputStream in, MultiMap map, int maxLength, int maxKeys) throws IOException
+ {
+ InputStreamReader input = new InputStreamReader(in, StandardCharsets.UTF_16);
+ StringWriter buf = new StringWriter(8192);
+ IO.copy(input, buf, maxLength);
+
+ // TODO implement maxKeys
+ decodeTo(buf.getBuffer().toString(), map, StandardCharsets.UTF_16);
+ }
+
/**
- * Decoded parameters to Map.
+ * Decoded parameters to MultiMap, using ISO8859-1 encodings.
*
* @param in InputSteam to read
* @param map MultiMap to add parameters to
- * @param maxLength maximum form length to decode
- * @param maxKeys the maximum number of keys to read or -1 for no limit
- * @throws IOException if unable to decode input stream
+ * @param maxLength maximum length of form to read
+ * @param maxKeys maximum number of keys to read or -1 for no limit
+ * @throws IOException if unable to decode inputstream as ISO8859-1
*/
- public static void decodeUtf8To(InputStream in, MultiMap map, int maxLength, int maxKeys)
+ public static void decode88591To(InputStream in, MultiMap map, int maxLength, int maxKeys)
throws IOException
{
synchronized (map)
{
- Utf8StringBuilder buffer = new Utf8StringBuilder();
+ StringBuffer buffer = new StringBuffer();
String key = null;
String value = null;
@@ -488,8 +640,8 @@ public static void decodeUtf8To(InputStream in, MultiMap map, int maxLen
switch ((char)b)
{
case '&':
- value = buffer.toReplacedString();
- buffer.reset();
+ value = buffer.length() == 0 ? "" : buffer.toString();
+ buffer.setLength(0);
if (key != null)
{
map.add(key, value);
@@ -507,190 +659,40 @@ else if (value != null && value.length() > 0)
case '=':
if (key != null)
{
- buffer.append((byte)b);
+ buffer.append((char)b);
break;
}
- key = buffer.toReplacedString();
- buffer.reset();
+ key = buffer.toString();
+ buffer.setLength(0);
break;
case '+':
- buffer.append((byte)' ');
+ buffer.append(' ');
break;
case '%':
- char code0 = (char)in.read();
- char code1 = (char)in.read();
- buffer.append(decodeHexByte(code0, code1));
+ int code0 = in.read();
+ int code1 = in.read();
+ buffer.append(decodeHexChar(code0, code1));
break;
default:
- buffer.append((byte)b);
+ buffer.append((char)b);
break;
}
if (maxLength >= 0 && (++totalLength > maxLength))
- throw new IllegalStateException("Form is too large");
+ throw new IllegalStateException(String.format("Form with too many keys [%d > %d]", map.size(), maxKeys));
}
if (key != null)
{
- value = buffer.toReplacedString();
- buffer.reset();
+ value = buffer.length() == 0 ? "" : buffer.toString();
+ buffer.setLength(0);
map.add(key, value);
}
else if (buffer.length() > 0)
{
- map.add(buffer.toReplacedString(), "");
- }
- }
- }
-
- public static void decodeUtf16To(InputStream in, MultiMap map, int maxLength, int maxKeys) throws IOException
- {
- InputStreamReader input = new InputStreamReader(in, StandardCharsets.UTF_16);
- StringWriter buf = new StringWriter(8192);
- IO.copy(input, buf, maxLength);
-
- // TODO implement maxKeys
- decodeTo(buf.getBuffer().toString(), map, StandardCharsets.UTF_16);
- }
-
- /**
- * Decoded parameters to Map.
- *
- * @param in the stream containing the encoded parameters
- * @param map the MultiMap to decode into
- * @param charset the charset to use for decoding
- * @param maxLength the maximum length of the form to decode
- * @param maxKeys the maximum number of keys to decode
- * @throws IOException if unable to decode input stream
- */
- public static void decodeTo(InputStream in, MultiMap map, String charset, int maxLength, int maxKeys)
- throws IOException
- {
- if (charset == null)
- {
- if (ENCODING.equals(StandardCharsets.UTF_8))
- decodeUtf8To(in, map, maxLength, maxKeys);
- else
- decodeTo(in, map, ENCODING, maxLength, maxKeys);
- }
- else if (StringUtil.__UTF8.equalsIgnoreCase(charset))
- decodeUtf8To(in, map, maxLength, maxKeys);
- else if (StringUtil.__ISO_8859_1.equalsIgnoreCase(charset))
- decode88591To(in, map, maxLength, maxKeys);
- else if (StringUtil.__UTF16.equalsIgnoreCase(charset))
- decodeUtf16To(in, map, maxLength, maxKeys);
- else
- decodeTo(in, map, Charset.forName(charset), maxLength, maxKeys);
- }
-
- /**
- * Decoded parameters to Map.
- *
- * @param in the stream containing the encoded parameters
- * @param map the MultiMap to decode into
- * @param charset the charset to use for decoding
- * @param maxLength the maximum length of the form to decode
- * @param maxKeys the maximum number of keys to decode
- * @throws IOException if unable to decode input stream
- */
- public static void decodeTo(InputStream in, MultiMap map, Charset charset, int maxLength, int maxKeys)
- throws IOException
- {
- //no charset present, use the configured default
- if (charset == null)
- charset = ENCODING;
-
- if (StandardCharsets.UTF_8.equals(charset))
- {
- decodeUtf8To(in, map, maxLength, maxKeys);
- return;
- }
-
- if (StandardCharsets.ISO_8859_1.equals(charset))
- {
- decode88591To(in, map, maxLength, maxKeys);
- return;
- }
-
- if (StandardCharsets.UTF_16.equals(charset)) // Should be all 2 byte encodings
- {
- decodeUtf16To(in, map, maxLength, maxKeys);
- return;
- }
-
- synchronized (map)
- {
- String key = null;
- String value = null;
-
- int c;
-
- int totalLength = 0;
-
- try (ByteArrayOutputStream2 output = new ByteArrayOutputStream2();)
- {
- int size = 0;
-
- while ((c = in.read()) > 0)
- {
- switch ((char)c)
- {
- case '&':
- size = output.size();
- value = size == 0 ? "" : output.toString(charset);
- output.setCount(0);
- if (key != null)
- {
- map.add(key, value);
- }
- else if (value != null && value.length() > 0)
- {
- map.add(value, "");
- }
- key = null;
- value = null;
- if (maxKeys > 0 && map.size() > maxKeys)
- throw new IllegalStateException(String.format("Form with too many keys [%d > %d]", map.size(), maxKeys));
- break;
- case '=':
- if (key != null)
- {
- output.write(c);
- break;
- }
- size = output.size();
- key = size == 0 ? "" : output.toString(charset);
- output.setCount(0);
- break;
- case '+':
- output.write(' ');
- break;
- case '%':
- int code0 = in.read();
- int code1 = in.read();
- output.write(decodeHexChar(code0, code1));
- break;
- default:
- output.write(c);
- break;
- }
-
- totalLength++;
- if (maxLength >= 0 && totalLength > maxLength)
- throw new IllegalStateException("Form is too large");
- }
-
- size = output.size();
- if (key != null)
- {
- value = size == 0 ? "" : output.toString(charset);
- output.setCount(0);
- map.add(key, value);
- }
- else if (size > 0)
- map.add(output.toString(charset), "");
+ map.add(buffer.toString(), "");
}
}
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8Appendable.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8Appendable.java
index d7f059839ccd..2c44105a3bc0 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8Appendable.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8Appendable.java
@@ -61,29 +61,29 @@ public abstract class Utf8Appendable
protected int _state = UTF8_ACCEPT;
private static final byte[] BYTE_TABLE =
- {
- // The first part of the table maps bytes to character classes that
- // to reduce the size of the transition table and create bitmasks.
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6, 6, 6, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
- };
+ {
+ // The first part of the table maps bytes to character classes that
+ // to reduce the size of the transition table and create bitmasks.
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6, 6, 6, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
+ };
private static final byte[] TRANS_TABLE =
- {
- // The second part is a transition table that maps a combination
- // of a state of the automaton and a character class to a state.
- 0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 24, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12,
- 12, 36, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12
- };
+ {
+ // The second part is a transition table that maps a combination
+ // of a state of the automaton and a character class to a state.
+ 0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 24, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12,
+ 12, 36, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12
+ };
private int _codep;
@@ -248,7 +248,7 @@ protected void appendByte(byte b) throws IOException
break;
case UTF8_REJECT:
- String reason = "byte " + TypeUtil.toHexString(b) + " in state " + (_state / 12);
+ final String reason = "byte " + TypeUtil.toHexString(b) + " in state " + (_state / 12);
_codep = 0;
_state = UTF8_ACCEPT;
_appendable.append(REPLACEMENT);
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8LineParser.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8LineParser.java
index c132ae8c040c..d54197f88f56 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8LineParser.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8LineParser.java
@@ -76,6 +76,7 @@ private boolean parseByte(byte b)
utf = new Utf8StringBuilder();
state = State.PARSE;
return parseByte(b);
+
case PARSE:
// not waiting on more UTF sequence parts.
if (utf.isUtf8SequenceComplete() && ((b == '\r') || (b == '\n')))
@@ -84,7 +85,8 @@ private boolean parseByte(byte b)
return parseByte(b);
}
utf.append(b);
- break;
+ return false;
+
case END:
if (b == '\n')
{
@@ -92,8 +94,10 @@ private boolean parseByte(byte b)
state = State.START;
return true;
}
- break;
+ return false;
+
+ default:
+ throw new IllegalStateException();
}
- return false;
}
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java
index e9fcce47b7fd..a8626a2bc27d 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java
@@ -166,8 +166,9 @@ public String getState()
return STOPPING;
case STATE_STOPPED:
return STOPPED;
+ default:
+ return null;
}
- return null;
}
public static String getState(LifeCycle lc)
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/Container.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/Container.java
index 8ebbb1671ff0..f348e95dc789 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/Container.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/Container.java
@@ -34,6 +34,15 @@ public interface Container
*/
public boolean addBean(Object o);
+ /**
+ * Adds the given bean, explicitly managing it or not.
+ *
+ * @param o The bean object to add
+ * @param managed whether to managed the lifecycle of the bean
+ * @return true if the bean was added, false if it was already present
+ */
+ boolean addBean(Object o, boolean managed);
+
/**
* @return the list of beans known to this aggregate
* @see #getBean(Class)
@@ -105,15 +114,6 @@ public interface Container
*/
boolean isManaged(Object bean);
- /**
- * Adds the given bean, explicitly managing it or not.
- *
- * @param o The bean object to add
- * @param managed whether to managed the lifecycle of the bean
- * @return true if the bean was added, false if it was already present
- */
- boolean addBean(Object o, boolean managed);
-
/**
* A listener for Container events.
* If an added bean implements this interface it will receive the events
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java
index 1eb91aafbfdd..835534f2d19f 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java
@@ -395,6 +395,10 @@ else if (isStarted())
case POJO:
newBean._managed = Managed.POJO;
+ break;
+
+ default:
+ throw new IllegalStateException(managed.toString());
}
}
catch (RuntimeException | Error e)
@@ -546,12 +550,6 @@ private void unmanage(Bean bean)
}
}
- @Override
- public Collection |