use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project buck by facebook.
the class Project method writeJsonConfig.
private void writeJsonConfig(File jsonTempFile, List<SerializableModule> modules, List<SerializablePrebuiltJarRule> libraries, List<SerializableAndroidAar> aars) throws IOException {
Map<String, Object> config = ImmutableMap.of("modules", modules, "libraries", libraries, "aars", aars, "java", createSerializableIntellijSettings(intellijConfig));
// Write out the JSON config to be consumed by the Python.
try (Writer writer = new FileWriter(jsonTempFile)) {
if (executionContext.getVerbosity().shouldPrintOutput()) {
ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
objectWriter.writeValue(writer, config);
} else {
objectMapper.writeValue(writer, config);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project hadoop by apache.
the class RumenToSLSConverter method generateSLSLoadFile.
private static void generateSLSLoadFile(String inputFile, String outputFile) throws IOException {
try (Reader input = new InputStreamReader(new FileInputStream(inputFile), "UTF-8")) {
try (Writer output = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
Iterator<Map> i = mapper.readValues(new JsonFactory().createParser(input), Map.class);
while (i.hasNext()) {
Map m = i.next();
output.write(writer.writeValueAsString(createSLSJob(m)) + EOL);
}
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project hadoop by apache.
the class RumenToSLSConverter method generateSLSNodeFile.
@SuppressWarnings("unchecked")
private static void generateSLSNodeFile(String outputFile) throws IOException {
try (Writer output = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
for (Map.Entry<String, Set<String>> entry : rackNodeMap.entrySet()) {
Map rack = new LinkedHashMap();
rack.put("rack", entry.getKey());
List nodes = new ArrayList();
for (String name : entry.getValue()) {
Map node = new LinkedHashMap();
node.put("node", name);
nodes.add(node);
}
rack.put("nodes", nodes);
output.write(writer.writeValueAsString(rack) + EOL);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project jackson-databind by FasterXML.
the class TestJDKSerialization method testObjectWriter.
public void testObjectWriter() throws IOException {
ObjectWriter origWriter = MAPPER.writer();
final String EXP_JSON = "{\"x\":2,\"y\":3}";
final MyPojo p = new MyPojo(2, 3);
assertEquals(EXP_JSON, origWriter.writeValueAsString(p));
String json = origWriter.writeValueAsString(new AnyBean().addEntry("a", "b"));
assertNotNull(json);
byte[] bytes = jdkSerialize(origWriter);
ObjectWriter writer2 = jdkDeserialize(bytes);
assertEquals(EXP_JSON, writer2.writeValueAsString(p));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project jackson-databind by FasterXML.
the class ObjectWriterTestBase method test.
protected void test(ObjectMapper mapper, String desc1, T1 inputValue1, Class<? extends T1> inputClass1, String desc2, T2 inputValue2, Class<? extends T2> inputClass2) throws Exception {
final int REPS;
{
final byte[] input1 = mapper.writeValueAsBytes(inputValue1);
final byte[] input2 = mapper.writeValueAsBytes(inputValue2);
// Let's try to guestimate suitable size, N megs of output
REPS = (int) ((double) (targetSizeMegs() * 1000 * 1000) / (double) input1.length);
System.out.printf("Read %d bytes to bind (%d as array); will do %d repetitions\n", input1.length, input2.length, REPS);
}
final ObjectWriter writer0 = mapper.writer().with(SerializationFeature.EAGER_SERIALIZER_FETCH);
final ObjectWriter writer1 = writer0.forType(inputClass1);
final ObjectWriter writer2 = writer0.forType(inputClass2);
int i = 0;
int roundsDone = 0;
final int TYPES = 2;
// Skip first 5 seconds
long startMeasure = System.currentTimeMillis() + 5000L;
System.out.print("Warming up");
final double[] timesMsec = new double[TYPES];
while (true) {
final int round = (i % TYPES);
final boolean lf = (++i % TYPES) == 0;
String msg;
ObjectWriter writer;
Object value;
switch(round) {
case 0:
msg = desc1;
writer = writer1;
value = inputValue1;
break;
case 1:
msg = desc2;
writer = writer2;
value = inputValue2;
break;
default:
throw new Error();
}
double msecs = testSer(REPS, value, writer);
// skip first N seconds to let results stabilize
if (startMeasure > 0L) {
if ((round != 0) || (System.currentTimeMillis() < startMeasure)) {
System.out.print(".");
continue;
}
startMeasure = 0L;
System.out.println();
System.out.println("Starting measurements...");
Thread.sleep(250L);
System.out.println();
}
timesMsec[round] += msecs;
if ((i % 17) == 0) {
System.out.println("[GC]");
Thread.sleep(100L);
System.gc();
Thread.sleep(100L);
}
System.out.printf("Test '%s' [hash: 0x%s] -> %.1f msecs\n", msg, hash, msecs);
Thread.sleep(50L);
if (!lf) {
continue;
}
if ((++roundsDone % 3) == 0) {
double den = (double) roundsDone;
System.out.printf("Averages after %d rounds (%s/%s): %.1f / %.1f msecs\n", roundsDone, desc1, desc2, timesMsec[0] / den, timesMsec[1] / den);
}
System.out.println();
}
}
Aggregations