Codota Logo
Streams
Code IndexAdd Codota to your IDE (free)

How to use
Streams
in
org.dihedron.core.streams

Best Java code snippets using org.dihedron.core.streams.Streams (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ScheduledThreadPoolExecutor s =
  • Codota Iconnew ScheduledThreadPoolExecutor(corePoolSize)
  • Codota IconThreadFactory threadFactory;new ScheduledThreadPoolExecutor(corePoolSize, threadFactory)
  • Codota IconString str;new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat(str).build())
  • Smart code suggestions by Codota
}
origin: org.dihedron.commons/base

/**
 * Copies all the bytes it can read from the input stream into the output
 * stream; input and output streams management (opening, flushing, closing)
 * are all up to the caller.
 * 
 * @param input
 *   an open and ready-to-be-read input stream.
 * @param output
 *   an open output stream.
 * @return
 *   the total number of bytes copied.
 * @throws IOException
 */
public static long copy(InputStream input, OutputStream output) throws IOException {
  return copy(input, output, false);
}

origin: org.dihedron.commons/base

/**
 * Returns an input stream from a string representing its path.
 * 
 * @param filepath
 *   a string representing the file path.
 * @return
 *   a {@code FileInputStream} object.
 * @throws FileNotFoundException
 */
public static InputStream fromFile(String filepath) throws FileNotFoundException {
  if(Strings.isValid(filepath)) {
    return fromFile(new File(filepath));
  }
  return null;
}

origin: org.dihedron.commons/dihedron-commons

  /**
   * @see org.dihedron.patterns.cache.Storage#clear()
   */
  @Override
  public void clear() {
    logger.debug("clearing storage");
    for(String resource : contents.keySet()) {
      Streams.safelyClose(contents.get(resource));
    }
    contents.clear();
  }    
}
origin: org.dihedron.commons/dihedron-commons

/**
 * Constructor.
 *
 * @param name
 *   the name of the library; the "&lt;library&gt;.properties" (where <&lt;library&gt;
 *   is the name of the library) will be loaded from the root of the classpath.
 */
protected Library(String name) {
  this.name = name;
  
  String path = PROPERTIES_FILE.replaceAll("\\$\\{library\\}", name);
  logger.trace("loading from '{}'", path);
  try(InputStream stream = Streams.fromURL(path)){
    properties.load(stream);
  } catch (IOException e) {
    logger.error("error loading library properties from input stream", e);
  } catch (PropertiesException e) {
    logger.error("error loading library properties from input stream", e);
  }        
}

origin: org.dihedron.commons/dihedron-commons

  if(input != null) {
    output = new ByteArrayOutputStream();
    long copied = Streams.copy(input, output);
    logger.trace("copied {} bytes from cache", copied);
    return output.toByteArray();
  throw new CacheException("error copying data from cache to byte array", e);
} finally {
  Streams.safelyClose(input);
  Streams.safelyClose(output);
origin: org.dihedron.commons/base

  String path = PROPERTIES_FILE.replaceAll("\\$\\{library\\}", name);
  logger.trace("loading from '{}'", path);
  stream = Streams.fromURL(path);
  properties.load(stream);
} catch (IOException e) {
origin: org.dihedron.commons/dihedron-commons

  if(output != null) {
    input = new ByteArrayInputStream(data);
    long copied = Streams.copy(input, output);
    logger.trace("copied {} bytes into cache", copied);
    return copied;
  throw new CacheException("error copying data from byte array to cache", e);
} finally {
  Streams.safelyClose(input);
  Streams.safelyClose(output);
origin: org.dihedron.commons/dihedron-commons

/**
 * Copies all the bytes it can read from the input stream into the output
 * stream; input and output streams management (opening, flushing, closing)
 * are all up to the caller.
 * 
 * @param input
 *   an open and ready-to-be-read input stream.
 * @param output
 *   an open output stream.
 * @return
 *   the total number of bytes copied.
 * @throws IOException
 */
public static long copy(InputStream input, OutputStream output) throws IOException {
  return copy(input, output, false);
}

origin: org.dihedron.commons/dihedron-core

  String path = PROPERTIES_FILE.replaceAll("\\$\\{library\\}", name);
  logger.trace("loading from '{}'", path);
  stream = Streams.fromURL(path);
  properties.load(stream);
} catch (IOException e) {
origin: org.dihedron.commons/dihedron-commons

/**
 * Returns an input stream from a string representing its path.
 * 
 * @param filepath
 *   a string representing the file path.
 * @return
 *   a {@code FileInputStream} object.
 * @throws FileNotFoundException
 */
public static InputStream fromFile(String filepath) throws FileNotFoundException {
  if(Strings.isValid(filepath)) {
    return fromFile(new File(filepath));
  }
  return null;
}

origin: org.dihedron.commons/dihedron-commons

/**
 * @see org.dihedron.patterns.cache.Storage#delete(org.dihedron.core.regex.Regex)
 */
@Override
public void delete(Regex regex) {
  Set<String> resources = new HashSet<String>(contents.keySet());
  for (String resource : resources) {
    if(regex.matches(resource)){
      logger.debug("removing resource '{}'", resource);
      Streams.safelyClose(contents.get(resource));
      contents.remove(resource);
    }
  }
}
  
origin: org.dihedron.commons/dihedron-core

/**
 * Copies all the bytes it can read from the input stream into the output
 * stream; input and output streams management (opening, flushing, closing)
 * are all up to the caller.
 * 
 * @param input
 *   an open and ready-to-be-read input stream.
 * @param output
 *   an open output stream.
 * @return
 *   the total number of bytes copied.
 * @throws IOException
 */
public static long copy(InputStream input, OutputStream output) throws IOException {
  return copy(input, output, false);
}

origin: org.dihedron.commons/dihedron-core

/**
 * Reads a resource from an URL, specified as a string; since this class makes
 * use of the URL factory, URLs may also represent resources in the class
 * path, re (in the format "classpath:org/dihedron/resources/MyResource.png").
 * 
 * @param url
 *   a string presenting an URL.
 * @return
 *   an input stream to access the URL.
 * @throws IOException
 *   if the URL is malformed or an error occurs opening the stream.
 */
public static InputStream fromURL(String url) throws IOException {
  if(Strings.isValid(url)) {
    return fromURL(URLFactory.makeURL(url));
  }
  return null;
}

origin: org.dihedron.commons/dihedron-core

/**
 * Returns an input stream from a string representing its path.
 * 
 * @param filepath
 *   a string representing the file path.
 * @return
 *   a {@code FileInputStream} object.
 * @throws FileNotFoundException
 */
public static InputStream fromFile(String filepath) throws FileNotFoundException {
  if(Strings.isValid(filepath)) {
    return fromFile(new File(filepath));
  }
  return null;
}

origin: org.dihedron.commons/dihedron-commons

/**
 * @see org.dihedron.patterns.cache.Storage#delete(java.lang.String, boolean)
 */
@Override
public void delete(String resource, boolean caseSensitive) {
  Set<String> resources = new HashSet<String>(contents.keySet());
  for (String string : resources) {
    if(caseSensitive && string.equals(resource)) {
      logger.debug("removing resource '{}'", resource);
      Streams.safelyClose(contents.get(resource));
      contents.remove(resource);
    } else if(!caseSensitive && string.equalsIgnoreCase(resource)){
      logger.debug("removing resource '{}'", resource);
      Streams.safelyClose(contents.get(resource));
      contents.remove(resource);                
    } else {
      logger.trace("keeping resource '{}'", resource);
    }
  }
}

origin: org.dihedron.commons/dihedron-commons

/**
 * Adds a file to the ZIP archive, given its content as an input stream.
 * 
 * @param zipEntry 
 *   name of the entry in the archive.
 * @param input 
 *   the stream from which data will be read to be added to the ZIP archive;
 *   the stream must be open and will not be closed once the operation is 
 *   complete, so it is up to the caller to release it.
 */
public void addFile(String zipEntry, InputStream input) throws IOException {
  if(input != null) {
    stream.putNextEntry(new ZipEntry(zipEntry));
    Streams.copy(input, stream);
  }
}
origin: org.dihedron.commons/base

/**
 * Reads a resource from an URL, specified as a string; since this class makes
 * use of the URL factory, URLs may also represent resources in the class
 * path, re (in the format "classpath:org/dihedron/resources/MyResource.png").
 * 
 * @param url
 *   a string presenting an URL.
 * @return
 *   an input stream to access the URL.
 * @throws IOException
 *   if the URL is malformed or an error occurs opening the stream.
 */
public static InputStream fromURL(String url) throws IOException {
  if(Strings.isValid(url)) {
    return fromURL(URLFactory.makeURL(url));
  }
  return null;
}

origin: org.dihedron.commons/dihedron-commons

/**
 * @see org.dihedron.patterns.cache.Storage#store(java.lang.String, java.io.InputStream)
 */
@Override
public OutputStream store(String resource) throws CacheException {
  if(Strings.isValid(resource)) {
    Streams.safelyClose(contents.get(resource));
    logger.debug("storing resource '{}'", resource);
    CacheOutputStream<ByteArrayOutputStream> stream = new CacheOutputStream<ByteArrayOutputStream>(new ByteArrayOutputStream());
    contents.put(resource, stream);
    return stream; 
  }
  return null;
}
origin: org.dihedron.commons/dihedron-commons

  /**
   * Dumps the response data as a string.
   * 
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
    try(InputStream input = connection.getInputStream(); ByteArrayOutputStream output = new ByteArrayOutputStream()) { 
      Streams.copy(input, output);
      String data = new String(output.toByteArray());
//            logger.trace("response data:\n{}", data);
      return data;
    } catch (IOException e) {
      logger.error("error reading response data from stream", e);
    }
    return null;
  }    
}
origin: org.dihedron.commons/dihedron-commons

/**
 * Reads a resource from an URL, specified as a string; since this class makes
 * use of the URL factory, URLs may also represent resources in the class
 * path, re (in the format "classpath:org/dihedron/resources/MyResource.png").
 * 
 * @param url
 *   a string presenting an URL.
 * @return
 *   an input stream to access the URL.
 * @throws IOException
 *   if the URL is malformed or an error occurs opening the stream.
 */
public static InputStream fromURL(String url) throws IOException {
  if(Strings.isValid(url)) {
    return fromURL(URLFactory.makeURL(url));
  }
  return null;
}

org.dihedron.core.streamsStreams

Javadoc

A class providing useful utility methods for manipulating streams.

Most used methods

  • copy
    Copies all the bytes it can read from the input stream into the output stream; input and output stre
  • fromFile
    Returns an input stream from a string representing its path.
  • fromURL
    Opens an input stream to the given URL.
  • safelyClose
    Tries to close the given stream; if any exception is thrown in the process, it suppresses it.

Popular in Java

  • Making http requests using okhttp
  • findViewById (Activity)
  • getSupportFragmentManager (FragmentActivity)
    Return the FragmentManager for interacting with fragments associated with this activity.
  • addToBackStack (FragmentTransaction)
  • FileOutputStream (java.io)
    A file output stream is an output stream for writing data to aFile or to a FileDescriptor. Whether
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • List (java.util)
    A List is a collection which maintains an ordering for its elements. Every element in the List has a
  • TimerTask (java.util)
    A task that can be scheduled for one-time or repeated execution by a Timer.
  • Runner (org.openjdk.jmh.runner)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now