brikar-server/src/main/java/com/truward/brikar/server/util/JettyResourceUtil.java
public static Resource createResource(String resourcePath) throws IOException {
    if (resourcePath.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
      return Resource.newClassPathResource(resourcePath.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()));
    } else if (resourcePath.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
      return Resource.newResource(new File(resourcePath.substring(ResourceUtils.FILE_URL_PREFIX.length())));
    } else if (resourcePath.startsWith("/")) {
      return Resource.newResource(new File(resourcePath));
    }

    try {
      if (Files.exists(Paths.get(resourcePath))) {
        return Resource.newResource(new File(resourcePath));
      }

      // path seem to be valid but nothing exists there
      throw new IOException("Missing file at resourcePath=" + resourcePath);
    } catch (InvalidPathException e) {
      throw new IOException("Invalid path or unknown protocol in resourcePath=" + resourcePath, e);
    }
  }
public static Resource createResource(String resourcePath) throws IOException {
    if (resourcePath.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
      return Resource.newClassPathResource(resourcePath.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()));
    } else if (resourcePath.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
      return Resource.newResource(new File(resourcePath.substring(ResourceUtils.FILE_URL_PREFIX.length())));
    } else if (resourcePath.startsWith("/")) {
      return Resource.newResource(new File(resourcePath));
    }

    try {
      if (Files.exists(Paths.get(resourcePath))) {
        return Resource.newResource(new File(resourcePath));
      }

      // path seem to be valid but nothing exists there
      throw new IOException("Missing file at resourcePath=" + resourcePath);
    } catch (InvalidPathException e) {
      throw new IOException("Invalid path or unknown protocol in resourcePath=" + resourcePath, e);
    }
  }
public static Resource createResource ( String resourcePath ) throws IOException { if ( resourcePath . startsWith ( ResourceUtils . CLASSPATH_URL_PREFIX ) ) { return Resource . newClassPathResource ( resourcePath . substring ( ResourceUtils . CLASSPATH_URL_PREFIX . length ( ) ) ) ; } else if ( resourcePath . startsWith ( ResourceUtils . FILE_URL_PREFIX ) ) { return Resource . newResource ( new File ( resourcePath . substring ( ResourceUtils . FILE_URL_PREFIX . length ( ) ) ) ) ; } else if ( resourcePath . startsWith ( "/" ) ) { return Resource . newResource ( new File ( resourcePath ) ) ; } try { if ( Files . exists ( Paths . get ( resourcePath ) ) ) { return Resource . newResource ( new File ( resourcePath ) ) ; } // path seem to be valid but nothing exists there throw new IOException ( "Missing file at resourcePath=" + resourcePath ) ; } catch ( InvalidPathException e ) { throw new IOException ( "Invalid path or unknown protocol in resourcePath=" + resourcePath , e ) ; } }
hidden
hidden