private static InputStream toInputStream(File storeFile) throws IOException { byte[] data = FileUtils.readFileToByteArray(storeFile); return new ByteArrayInputStream(data); } }
@Nullable public static byte[] getBytesFromFile(@NotNull String filename) { try { return FileUtils.readFileToByteArray(new File(filename)); } catch (Exception e) { return null; } }
@Nullable public static byte[] getBytesFromFile(@NotNull String filename) { try { return FileUtils.readFileToByteArray(new File(filename)); } catch (Exception e) { return null; } }
public FileResultModel(File file, int fileType) { if (fileType != FILE_TYPE_BINARY && fileType != FILE_TYPE_TEXT) { throw new IllegalArgumentException("Unsupported file type is specified."); } this.filename = file.getName(); try { this.data = FileUtils.readFileToByteArray(file); } catch (IOException e) { throw new RuntimeException("Unable to read file: " + file.getAbsolutePath(), e); } this.length = data.length; this.type = fileType; }
@SuppressWarnings("unchecked") public static Object readLocalObject(String topologyId, String readFile) throws IOException { String errMsg = "Failed to get topology configuration of " + topologyId + " file:" + readFile; byte[] bconf = FileUtils.readFileToByteArray(new File(readFile)); if (bconf == null) { errMsg += ", failed to read"; LOG.error(errMsg); throw new IOException(errMsg); } Object ret; try { ret = Utils.javaDeserialize(bconf); } catch (Exception e) { errMsg += ", failed to serialize the data"; LOG.error(errMsg); throw new IOException(errMsg); } return ret; }
public TorrentMetadata parseFromFile(File torrentFile) throws IOException { byte[] fileContent = FileUtils.readFileToByteArray(torrentFile); return parse(fileContent); }
private static void addCompiledClasses(List<CompiledSourceCode> ret, String pkgName, File dir) throws IOException { for (File file : dir.listFiles()) { String filename = file.getName(); if (file.isDirectory()) { String qname = pkgName + filename + "."; addCompiledClasses(ret, qname, file); } else if (filename.endsWith(".class")) { String qname = pkgName + filename.substring(0, filename.length() - 6); ret.add(new CompiledSourceCode(qname, FileUtils.readFileToByteArray(file))); } else { System.err.println("Unexpected file : " + file.getAbsolutePath()); } } }
public synchronized Map<Object, Object> snapshot() throws IOException { String latestPath = _vs.mostRecentVersionPath(); if(latestPath==null) return new HashMap<Object, Object>(); return (Map<Object, Object>) Utils.deserialize(FileUtils.readFileToByteArray(new File(latestPath))); }
public static Map read_supervisor_storm_conf(Map conf, String storm_id) throws IOException { String stormroot = StormConfig .supervisor_stormdist_root(conf, storm_id); String conf_path = StormConfig.supervisor_sotrmconf_path(stormroot); // String topology_path = // StormConfig.supervisor_stormcode_path(stormroot); Map rtn = new HashMap(); rtn.putAll(conf); rtn.putAll((Map) Utils.deserialize(FileUtils .readFileToByteArray(new File(conf_path)))); return rtn; }
public static long read_supervisor_topology_timestamp(Map conf, String topologyId) throws IOException { String stormRoot = supervisor_stormdist_root(conf, topologyId); String timeStampPath = stormts_path(stormRoot); byte[] data = FileUtils.readFileToByteArray(new File(timeStampPath)); return JStormUtils.bytesToLong(data); }
public static long read_nimbus_topology_timestamp(Map conf, String topologyId) throws IOException { String stormRoot = masterStormdistRoot(conf, topologyId); String timeStampPath = stormts_path(stormRoot); byte[] data = FileUtils.readFileToByteArray(new File(timeStampPath)); return JStormUtils.bytesToLong(data); }
public static StormTopology read_supervisor_topology(Map conf, String topologyid) throws IOException { String topologyroot = StormConfig.supervisor_stormdist_root(conf, topologyid); String topology_path = StormConfig .supervisor_stormcode_path(topologyroot); return (StormTopology) Utils.deserialize(FileUtils .readFileToByteArray(new File(topology_path))); }
@Test public void testCopyFileToOutputStream() throws Exception { final ByteArrayOutputStream destination = new ByteArrayOutputStream(); FileUtils.copyFile(testFile1, destination); assertEquals("Check Full copy size", testFile1Size, destination.size()); final byte[] expected = FileUtils.readFileToByteArray(testFile1); Assert.assertArrayEquals("Check Full copy", expected, destination.toByteArray()); }
private Map<Object, Object> deserializeLatestVersion() throws IOException { String latestPath = _vs.mostRecentVersionPath(); Long latestVersion = _vs.mostRecentVersion(); Map<Object, Object> result = new HashMap<>(); while (latestPath != null) { byte[] serialized = FileUtils.readFileToByteArray(new File(latestPath)); if (serialized.length == 0) { LOG.warn("LocalState file '{}' contained no data, skip this state", latestPath); latestPath = _vs.mostRecentVersionPath(latestVersion - 1); latestVersion = _vs.mostRecentVersion(latestVersion - 1); } else { result = (Map<Object, Object>) Utils.javaDeserialize(serialized); break; } } return result; }
@Override public void run(String[] args, Map<String, Object> conf, String command) throws Exception { for (String arg: args) { System.out.println(arg + ":"); StormTopology topo; File f = new File(arg); if (f.exists()) { topo = Utils.deserialize(FileUtils.readFileToByteArray(f), StormTopology.class); } else { //assume it is a topology id final String key = ConfigUtils.masterStormCodeKey(arg); try (BlobStore store = ServerUtils.getNimbusBlobStore(conf, NimbusInfo.fromConf(conf), null)) { topo = Utils.deserialize(store.readBlob(key, Nimbus.NIMBUS_SUBJECT), StormTopology.class); } } System.out.println(prettyPrint(topo)); } }
private static void verifySameContent(TestResponse response, File file) throws IOException { assertThat(IOUtils.toByteArray(response.getInputStream())).isEqualTo(FileUtils.readFileToByteArray(file)); } }
@Test public void testReadFileToByteArray() throws Exception { final File file = new File(getTestDirectory(), "read.txt"); final FileOutputStream out = new FileOutputStream(file); out.write(11); out.write(21); out.write(31); out.close(); final byte[] data = FileUtils.readFileToByteArray(file); assertEquals(3, data.length); assertEquals(11, data[0]); assertEquals(21, data[1]); assertEquals(31, data[2]); }
public static SharedTorrent fromFile(File source, PieceStorage pieceStorage, TorrentStatistic torrentStatistic) throws IOException { byte[] data = FileUtils.readFileToByteArray(source); TorrentMetadata torrentMetadata = new TorrentParser().parse(data); return new SharedTorrent(torrentMetadata, pieceStorage, DEFAULT_REQUEST_STRATEGY, torrentStatistic, new EventDispatcher()); }
trustStorePwdBytes = FileUtils.readFileToByteArray(serverSslConfig.getClientAuthTrustStorePasswordFile());
/** * Enqueue download of file with a MD5 that may not be returned (null) or not valid */ private void enqueueDownload(File file, @Nullable String md5) throws IOException { Buffer body = new Buffer(); body.write(FileUtils.readFileToByteArray(file)); MockResponse response = new MockResponse().setBody(body); if (md5 != null) { response.setHeader("Sonar-MD5", md5); } server.enqueue(response); }