Java Class Loader readAll(ClassLoader cl, String path)

Here you can find the source of readAll(ClassLoader cl, String path)

Description

read All

License

Open Source License

Declaration

public static String readAll(ClassLoader cl, String path) throws IOException, NullPointerException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;

public class Main {
    public static String readAll(ClassLoader cl, String path) throws IOException, NullPointerException {
        FileReader reader = null;
        try {/*  ww  w  .  j  av  a 2 s . com*/
            URL url = cl.getResource(path);
            if (url == null)
                throw new NullPointerException("Url not found");

            File file = new File(url.getFile());
            reader = new FileReader(file);
            char[] buffer = new char[1024];
            StringBuilder builder = new StringBuilder();

            int bytesRead;
            while ((bytesRead = reader.read(buffer)) > 0) {
                builder.append(buffer, 0, bytesRead);
            }
            return builder.toString();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

  1. loadProperties(final Properties properties, final String fileName, final ClassLoader cl)
  2. loadStyleSheet(Class type)
  3. loadTextFile(Class relToThisClass, String relFileName)
  4. pathFromLoaders(final Class clazz)
  5. print(ClassLoader loader)
  6. readBytecodeForClass(ClassLoader loader, String className, boolean mustExist)
  7. resolveClientClassLoader(Map env)
  8. resolveServerClassLoader(Map env, MBeanServer mbs)
  9. scanPackage(ClassLoader classLoader, Package pkg)