You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

  1. package com.sothr.imagetools.engine.util;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import java.io.InputStream;
  5. import java.net.URL;
  6. /**
  7. * Seamlessly handle resource loading
  8. *
  9. * Created by drew on 1/5/14.
  10. */
  11. public class ResourceLoader {
  12. private static final ResourceLoader instance = new ResourceLoader();
  13. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  14. private ResourceLoader() {
  15. logger.info("Created Resource Loader");
  16. }
  17. public static ResourceLoader get() {
  18. return instance;
  19. }
  20. public URL getResource(String location) {
  21. logger.debug(String.format("Attempting to load resource: %s", location));
  22. return Thread.currentThread().getContextClassLoader().getResource(location);
  23. }
  24. public InputStream getResourceStream(String location) {
  25. logger.debug(String.format("Attempting to get stream for resource: %s",location));
  26. return Thread.currentThread().getContextClassLoader().getResourceAsStream(location);
  27. }
  28. }