List of usage examples for org.apache.commons.lang3 SerializationUtils serialize
public static void serialize(final Serializable obj, final OutputStream outputStream)
Serializes an Object to the specified stream.
The stream will be closed once the object is written.
From source file:net.spfbl.http.ServerHTTP.java
public synchronized void store() { try {/*ww w . j a v a 2 s. c om*/ long time = System.currentTimeMillis(); File file = new File("./data/url.map"); if (MAP.isEmpty()) { file.delete(); } else { FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(MAP, outputStream); } finally { outputStream.close(); } Server.logStore(time, file); } } catch (Exception ex) { Server.logError(ex); } }
From source file:net.spfbl.whois.AutonomousSystem.java
/** * Armazenamento de cache em disco./*www . ja v a 2s . c om*/ */ public static void store() { if (AS_CHANGED) { try { // Server.logTrace("storing as.map"); long time = System.currentTimeMillis(); HashMap<String, AutonomousSystem> map = getMap(); File file = new File("./data/as.map"); FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(map, outputStream); // Atualiza flag de atualizao. AS_CHANGED = false; } finally { outputStream.close(); } Server.logStore(time, file); } catch (Exception ex) { Server.logError(ex); } } }
From source file:net.spfbl.whois.Domain.java
private static void storeDomain() { if (DOMAIN_CHANGED) { try {// ww w . ja va 2 s. c o m // Server.logTrace("storing domain.map"); long time = System.currentTimeMillis(); File file = new File("./data/domain.map"); HashMap<String, Domain> map = getDomainMap(); FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(map, outputStream); // Atualiza flag de atualizao. DOMAIN_CHANGED = false; } finally { outputStream.close(); } Server.logStore(time, file); } catch (Exception ex) { Server.logError(ex); } } }
From source file:net.spfbl.whois.Domain.java
private static void storeTLD() { if (TLD_CHANGED) { try {/* ww w . j a v a2s . c om*/ // Server.logTrace("storing tld.map"); long time = System.currentTimeMillis(); File file = new File("./data/tld.set"); TreeSet<String> set = getSetTLD(); FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(set, outputStream); // Atualiza flag de atualizao. TLD_CHANGED = false; } finally { outputStream.close(); } Server.logStore(time, file); } catch (Exception ex) { Server.logError(ex); } } }
From source file:net.spfbl.whois.Handle.java
/** * Armazenamento de cache em disco./*from w ww. j av a2 s. co m*/ */ public static void store() { if (CHANGED) { try { // Server.logTrace("storing handle.map"); long time = System.currentTimeMillis(); HashMap<String, Handle> map = getMap(); File file = new File("./data/handle.map"); FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(map, outputStream); // Atualiza flag de atualizao. CHANGED = false; } finally { outputStream.close(); } Server.logStore(time, file); } catch (Exception ex) { Server.logError(ex); } } }
From source file:net.spfbl.whois.NameServer.java
/** * Armazenamento de cache em disco./*www . j a v a2s .c o m*/ */ public static void store() { if (NS_CHANGED) { try { // Server.logTrace("storing ns.map"); long time = System.currentTimeMillis(); HashMap<String, NameServer> map = getMap(); File file = new File("./data/ns.map"); FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(map, outputStream); // Atualiza flag de atualizao. NS_CHANGED = false; } finally { outputStream.close(); } Server.logStore(time, file); } catch (Exception ex) { Server.logError(ex); } } }
From source file:net.spfbl.whois.Owner.java
/** * Armazenamento de cache em disco./*from w w w .j a v a2s . c o m*/ */ public static void store() { if (OWNER_CHANGED) { try { // Server.logTrace("storing owner.map"); long time = System.currentTimeMillis(); HashMap<String, Owner> map = getMap(); File file = new File("./data/owner.map"); FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(map, outputStream); // Atualiza flag de atualizao. OWNER_CHANGED = false; } finally { outputStream.close(); } Server.logStore(time, file); } catch (Exception ex) { Server.logError(ex); } } }
From source file:net.spfbl.whois.SubnetIPv4.java
/** * Armazenamento de cache em disco./*w ww . java 2 s . c om*/ */ public static void store() { if (CHANGED) { try { // Server.logTrace("storing subnet4.map"); long time = System.currentTimeMillis(); TreeMap<Long, SubnetIPv4> map = getMap(); File file = new File("./data/subnet4.map"); FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(map, outputStream); // Atualiza flag de atualizao. CHANGED = false; } finally { outputStream.close(); } Server.logStore(time, file); } catch (Exception ex) { Server.logError(ex); } } }
From source file:net.spfbl.whois.SubnetIPv6.java
/** * Armazenamento de cache em disco./*w ww . j av a2s.c o m*/ */ public static void store() { if (CHANGED) { try { // Server.logTrace("storing subnet6.map"); long time = System.currentTimeMillis(); TreeMap<String, SubnetIPv6> map = getMap(); File file = new File("./data/subnet6.map"); FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(map, outputStream); // Atualiza flag de atualizao. CHANGED = false; } finally { outputStream.close(); } Server.logStore(time, file); } catch (Exception ex) { Server.logError(ex); } } }
From source file:org.apache.beam.runners.apex.ApexYarnLauncher.java
protected AppHandle launchApp(LaunchParams params) throws IOException { File tmpFile = File.createTempFile("beam-runner-apex", "params"); tmpFile.deleteOnExit();/*w w w . java 2s. c o m*/ try (FileOutputStream fos = new FileOutputStream(tmpFile)) { SerializationUtils.serialize(params, fos); } if (params.getCmd() == null) { ApexYarnLauncher.main(new String[] { tmpFile.getAbsolutePath() }); } else { String cmd = params.getCmd() + " " + tmpFile.getAbsolutePath(); ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream(); LOG.info("Executing: {} with {}", cmd, params.getEnv()); ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd); Map<String, String> env = pb.environment(); env.putAll(params.getEnv()); Process p = pb.start(); ProcessWatcher pw = new ProcessWatcher(p); InputStream output = p.getInputStream(); InputStream error = p.getErrorStream(); while (!pw.isFinished()) { IOUtils.copy(output, consoleOutput); IOUtils.copy(error, consoleOutput); } if (pw.rc != 0) { String msg = "The Beam Apex runner in non-embedded mode requires the Hadoop client" + " to be installed on the machine from which you launch the job" + " and the 'hadoop' script in $PATH"; LOG.error(msg); throw new RuntimeException( "Failed to run: " + cmd + " (exit code " + pw.rc + ")" + "\n" + consoleOutput.toString()); } } return new AppHandle() { @Override public boolean isFinished() { // TODO (future PR): interaction with child process LOG.warn("YARN application runs asynchronously and status check not implemented."); return true; } @Override public void shutdown(ShutdownMode arg0) throws LauncherException { // TODO (future PR): interaction with child process throw new UnsupportedOperationException(); } }; }