示例#1
0
  /**
   * Registers a helper.
   *
   * @param classLoader The classloader to use.
   * @param configUrl Configuration URL to parse
   * @param helpers The list of helpers to update.
   * @param constructorClass The constructor parameter class to look for.
   */
  public void registerHelpers(
      ClassLoader classLoader, java.net.URL configUrl, List<?> helpers, Class<?> constructorClass) {
    try {
      BufferedReader reader = null;
      try {
        reader =
            new BufferedReader(
                new InputStreamReader(configUrl.openStream(), "utf-8"), IoUtils.getBufferSize());
        String line = reader.readLine();

        while (line != null) {
          registerHelper(classLoader, getProviderClassName(line), helpers, constructorClass);
          line = reader.readLine();
        }
      } catch (IOException e) {
        Context.getCurrentLogger()
            .log(Level.SEVERE, "Unable to read the provider descriptor: " + configUrl.toString());
      } finally {
        if (reader != null) {
          reader.close();
        }
      }
    } catch (IOException ioe) {
      Context.getCurrentLogger().log(Level.SEVERE, "Exception while detecting the helpers.", ioe);
    }
  }
  /**
   * Exhaust the content of the representation by reading it and silently discarding anything read.
   * By default, it relies on {@link #getStream()} and closes the retrieved stream in the end.
   *
   * @return The number of bytes consumed or -1 if unknown.
   */
  public long exhaust() throws IOException {
    long result = -1L;

    if (isAvailable()) {
      InputStream is = getStream();
      result = IoUtils.exhaust(is);
      is.close();
    }

    return result;
  }
 /**
  * Returns the size effectively available. This returns the same value as {@link #getSize()} if no
  * range is defined, otherwise it returns the size of the range using {@link Range#getSize()}.
  *
  * @return The available size.
  */
 public long getAvailableSize() {
   return IoUtils.getAvailableSize(this);
 }
 /**
  * Reads the full inputStream and returns an byte-array of it
  *
  * @param inputStream
  * @return
  * @throws IOException
  */
 public static byte[] getByteArray(InputStream inputStream) throws IOException {
   ByteArrayOutputStream byteStream = new ByteArrayOutputStream(4096);
   IoUtils.copy(inputStream, byteStream);
   return byteStream.toByteArray();
 }