private static boolean canSerialize(Object value, ObjectMapper objectMapper) { if (value == null) { return true; } // Jackson is not smart enough in the canSerialize check (especially with collections) so // the only good way to check if something can be serialized it to serialize it // We could save off the serialized data but it looks wrong when pretty printing is enabled try { objectMapper.writeValue(new NullOutputStream(), value); return true; } catch (Exception e) { return false; } }
private static boolean canSerialize(Object value, ObjectMapper objectMapper) { if (value == null) { return true; } // Jackson is not smart enough in the canSerialize check (especially with collections) so // the only good way to check if something can be serialized it to serialize it // We could save off the serialized data but it looks wrong when pretty printing is enabled try { objectMapper.writeValue(new NullOutputStream(), value); return true; } catch (Exception e) { return false; } }
private static boolean canSerialize(Object value, ObjectMapper objectMapper) { if (value == null) { return true; } // Jackson is not smart enough in the canSerialize check (especially with collections) so // the only good way to check if something can be serialized it to serialize it // We could save off the serialized data but it looks wrong when pretty printing is enabled try { objectMapper.writeValue(new NullOutputStream(), value); return true; } catch (Exception e) { return false; } }
public TrHash(final Object toHash, final int maxSize) throws TrSerializableException { MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); digest.reset(); final DataOutputStream digOS = new DataOutputStream(new DigestOutputStream(new NullOutputStream(), digest)); TrSerializer.serializeTo(toHash, digOS); hash = digest.digest(); } catch (final NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (final IOException e) { throw new RuntimeException(e); } }
public static void main(String[] args) { String programName = System.getProperty("script", "ConfigurationJsonTool"); Set<String> validArgument = Sets.newHashSet(); validArgument.add(CDAP_CONFIG); validArgument.add(SECURITY_CONFIG); if (args.length != 1 || !(validArgument.contains(args[0]))) { System.err.println(String.format("Usage: %s (%s | %s)", programName, CDAP_CONFIG, SECURITY_CONFIG)); System.exit(1); } PrintStream stdout = System.out; // Redirect the stdout to null to suppress any log outputs generated during the json generation System.setOut(new PrintStream(new NullOutputStream())); StringBuilder output = new StringBuilder(); exportToJson(args[0], output); // Restore the stdout System.setOut(stdout); System.out.print(output); } }
/** * Calculate InputStream size by reading through it * * @param in * @return Size of the data * @throws IOException */ public static long getInputStreamSize(InputStream in) throws IOException { CountingInputStream cin = new CountingInputStream(in); ByteStreams.copy(cin, new NullOutputStream()); return cin.getCount(); }
private static int[] computeTrailerSizeByVersion() { int versionToSize[] = new int[HFile.MAX_FORMAT_VERSION + 1]; for (int version = MIN_FORMAT_VERSION; version <= MAX_FORMAT_VERSION; ++version) { FixedFileTrailer fft = new FixedFileTrailer(version, HFileBlock.MINOR_VERSION_NO_CHECKSUM); DataOutputStream dos = new DataOutputStream(new NullOutputStream()); try { fft.serialize(dos); } catch (IOException ex) { // The above has no reason to fail. throw new RuntimeException(ex); } versionToSize[version] = dos.size(); } return versionToSize; }
public static void dumpShort(PrintStream out, Resource resource) throws IOException { MetaData m = resource.getMetaData(); // out.println("Headers Before"); // out.print(m.toString()); long bytes = StreamCopy.copy(resource.getInputStream(), new NullOutputStream()); out.println("Resource Was:"+bytes+" Long"); out.println("[\n]Headers After"); out.print(m.toString()); }
public static void initializeLogging(boolean debug) throws IOException { // unhook out and err while initializing logging or logger will print to them PrintStream out = System.out; PrintStream err = System.err; try { if (debug) { Logging logging = new Logging(); logging.initialize(new LoggingConfiguration()); } else { System.setOut(new PrintStream(new NullOutputStream())); System.setErr(new PrintStream(new NullOutputStream())); Logging logging = new Logging(); logging.initialize(new LoggingConfiguration()); logging.disableConsole(); } } finally { System.setOut(out); System.setErr(err); } } }
@Test public void callableShouldBeRemotable() throws IOException { givenACallable(); // WHEN callable is serialized ObjectOutputStream oos = new ObjectOutputStream(new NullOutputStream()); oos.writeObject(callable); // THEN no NotSerializableException should have been thrown oos.close(); }
public void output(Resource resource) throws IOException { NullOutputStream nullo = new NullOutputStream(); CountingOutputStream co = new CountingOutputStream(nullo); StreamCopy.copy(resource.getInputStream(), co); long bytes = co.getCount(); if(bytes > 0) { LOG.info(bytes + " unconsumed bytes in Resource InputStream."); } try { out.println(resource.getMetaData().getTopMetaData().toString(1)); } catch (JSONException e) { LOG.warning(e.getMessage()); } } }
public void output(Resource resource) throws IOException { NullOutputStream nullo = new NullOutputStream(); CountingOutputStream co = new CountingOutputStream(nullo); try {
@Test public void testResultRowNumWhenSelectingOnPartitionedTable() throws Exception { try (TajoCli cli2 = new TajoCli(cluster.getConfiguration(), new String[]{}, null, System.in, new NullOutputStream(), new NullOutputStream())) { cli2.executeScript("create table region_part (r_regionkey int8, r_name text) " + "partition by column (r_comment text) as select * from region"); setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); tajoCli.executeScript("select r_comment from region_part where r_comment = 'hs use ironic, even requests. s'"); String consoleResult = new String(out.toByteArray()); assertOutputResult(consoleResult); } finally { tajoCli.executeScript("drop table region_part purge"); } }
@Test(expectedExceptions = InvalidEventException.class, expectedExceptionsMessageRegExp = "Cycle detected in event data:.*") public void testCircularEvent() throws Exception { eventWriter.writeEvents(createEventGenerator(ImmutableList.of(new CircularEventClass())), new NullOutputStream()); }
@Test public void testSerialize() throws IOException { JsonEventSerializer serializer = new JsonEventSerializer(PrivateEvent.class); JsonGenerator generator = new JsonFactory().createJsonGenerator(new NullOutputStream()); serializer.serialize(new PrivateEvent(), generator); }
public void output(Resource resource) throws IOException { NullOutputStream nullo = new NullOutputStream(); CountingOutputStream co = new CountingOutputStream(nullo); try {
@Test(expectedExceptions = InvalidEventException.class, expectedExceptionsMessageRegExp = "Cycle detected in event data:.*") public void testChainedCircularEvent() throws Exception { ChainedPart a = new ChainedPart("a"); ChainedPart b = new ChainedPart("b"); ChainedPart c = new ChainedPart("c"); a.setPart(b); b.setPart(c); c.setPart(a); ChainedCircularEventClass event = new ChainedCircularEventClass(a); eventWriter.writeEvents(createEventGenerator(ImmutableList.of(event)), new NullOutputStream()); }