Code example for InputSource

Methods: getByteStream, getCharacterStream

0
  /** 
   * @noinspection IOResourceOpenedButNotSafelyClosed 
   */ 
  private byte[] extractData(final InputSource input) throws IOException
  { 
    final InputStream byteStream = input.getByteStream();
    if (byteStream != null)
    { 
      try 
      { 
        final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream();
        IOUtils.getInstance().copyStreams(byteStream, bout);
        return bout.toByteArray();
      } 
      finally 
      { 
        byteStream.close();
      } 
    } 
 
    final Reader characterStream = input.getCharacterStream();
    if (characterStream == null)
    { 
      throw new IOException
          ("InputSource has neither an Byte nor a CharacterStream"); 
    }