Utils.java 796 B

1234567891011121314151617181920212223242526272829303132333435
  1. package hello;
  2. import com.dslplatform.json.JsonWriter;
  3. import javax.servlet.http.HttpServletRequest;
  4. abstract class Utils {
  5. private static final ThreadLocal<Context> threadContext = ThreadLocal.withInitial(Context::new);
  6. private static final ThreadLocal<JsonWriter> threadJson = ThreadLocal.withInitial(JsonWriter::new);
  7. static Context getContext() {
  8. return threadContext.get();
  9. }
  10. static JsonWriter getJson() {
  11. JsonWriter json = threadJson.get();
  12. json.reset();
  13. return json;
  14. }
  15. static int parseBoundParam(HttpServletRequest request) {
  16. int count = 1;
  17. try {
  18. count = Integer.parseInt(request.getParameter("queries"));
  19. if (count > 500) {
  20. count = 500;
  21. } else if (count < 1) {
  22. count = 1;
  23. }
  24. } catch (NumberFormatException ignore) {
  25. }
  26. return count;
  27. }
  28. }