Interface DataFetcher

  • All Known Implementing Classes:
    AbstractBufferedDataFetcher, AbstractDataFetcher, BufferedDataFetcher

    public interface DataFetcher
    A DataFetcher can fetch the entire content of a given InputStream into a fresh byte[] or copy it into a given OutputStream.

    It is, among other things, intended as a replacement for IOUtils.toByteArray() to perform the everyday and menial task of reading an entire InputStream.

    Since the class sun.misc.IOUtils, which provides this functionality, is not a part of the official Java specification, usages of this class will usually yield a compiler warning like "The type 'IOUtils' is not API" and might break at runtime, if a runtime environment other than the Oracle JRE is used.

    All methods take optional parameters to specify the buffer size and to specify, whether the provided streams should be closed afterwards. This allows to write compact code like

     {
            foo.setContent(fetcher.fetch(new FileInputStream(file), true));
     }
     
    instead of unnecessarily verbose code like
     {
            InputStream in = new FileInputStream(file);
            foo.setContent(fetcher.fetch(in));
            in.close();
     }
     
    Since:
    4.0.0
    Author:
    Torsten Krause (tk at markenwerk dot net)