Guest User

Untitled

a guest
Nov 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. @ApplicationPath("api")
  2. public class PerformaApiApplication extends Application {
  3.  
  4. @Override
  5. public Set<Class<?>> getClasses() {
  6. final ClassLoader loader = this.getClass().getClassLoader();
  7. final Set<Class<?>> services = new HashSet<Class<?>>();
  8. for (String className : readClasses()) {
  9. try {
  10. final Class<?> clazz = loader.loadClass(className);
  11. services.add(clazz);
  12. } catch (Throwable t) {
  13. throw new RuntimeException("Could not load: "+className, t);
  14. }
  15. }
  16.  
  17. return services;
  18. }
  19.  
  20. private static Set<String> readClasses() {
  21. final Set<String> classNames = new HashSet<String>();
  22.  
  23. try {
  24. byte[] data = IOUtils.toByteArray(PerformaApiApplication.class.getResourceAsStream("/a.bin"));
  25. data = ZlibUtils.inflate(data);
  26. String str = new String(data);
  27. BufferedReader br = new BufferedReader(new StringReader(str));
  28. String line = null;
  29. while ((line = br.readLine()) != null) {
  30. if (line.trim().length() > 0) {
  31. String[] keyval = line.split("=");
  32. if (keyval.length == 2) {
  33. String route = keyval[0];
  34. String clazz = keyval[1];
  35. classNames.add(clazz);
  36. }
  37. }
  38. }
  39. } catch (Exception e) {
  40. throw new RuntimeException(e);
  41. }
  42. return classNames;
  43. }
  44. }
Add Comment
Please, Sign In to add comment