All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nitorcreations.willow.protocols.property.PropertyUrlConnection Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.nitorcreations.willow.protocols.property;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Properties;


public class PropertyUrlConnection extends URLConnection {
  public static final ThreadLocal currentProperties = new ThreadLocal<>();

  protected PropertyUrlConnection(URL url) {
    super(url);
  }
  @Override
  public void connect() throws IOException {
  }
  @Override
  public InputStream getInputStream() throws IOException {
    String property = null;
    if (currentProperties.get() != null) {
      property = currentProperties.get().getProperty(url.getPath());
    }
    if (property == null) {
      throw new IOException("Property '" + url.getPath() + "' not found");
    }
    return new ByteArrayInputStream(property.getBytes(StandardCharsets.UTF_8));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy