DataDownloader { public static byte[] downloadData(final String ds) throws IOException { if (ds == null) { throw new IllegalArgumentException("La fuente de datos no puede ser nula"); } final String dataSource = ds.trim(); if (dataSource.startsWith("http: return UrlHttpManagerFactory.getInstalledManager().readUrl(dataSource, UrlHttpMethod.GET); } if (dataSource.startsWith("ftp: final InputStream ftpStream = new URL(dataSource).openStream(); final byte[] data = AOUtil.getDataFromInputStream(ftpStream); ftpStream.close(); return data; } if (dataSource.startsWith("file:/")) { try { final InputStream is = AOUtil.loadFile(new URI(dataSource)); final InputStream bis = new BufferedInputStream(is); final byte[] ret = AOUtil.getDataFromInputStream(bis); bis.close(); is.close(); return ret; } catch (final URISyntaxException e) { throw new IOException( "Error leyendo el fichero (" + dataSource + "): " + e, e ); } } if (Base64.isBase64(dataSource.getBytes())) { Logger.getLogger("es.gob.afirma").info("El contenido a obtener es Base64"); try { return Base64.decode(dataSource.replace("_", "/").replace("-", "+")); } catch (final Exception e) { Logger.getLogger("es.gob.afirma").warning("Los datos introducidos no se pueden tratar como base 64: " + e); } } return dataSource.getBytes(); } private  DataDownloader(); static byte[] downloadData(final String ds);  }
@SuppressWarnings("static-method") @Test public void testDataDownloaderFile() throws Exception { final byte[] data = DataDownloader.downloadData( "file: ); System.out.println(new String(data)); }