@Override public void save(Config config) { IOCallback.execute(() -> { Path temp = Files.createTempFile(UUID.randomUUID().toString(), ".tmp"); try(OutputStream fout = Files.newOutputStream(temp)){ JaxbUtil.marshalWithNoValidation(config, fout); } Files.copy(temp, path,StandardCopyOption.REPLACE_EXISTING); return null; }); } }
@Override public void save(Config config) { IOCallback.execute(() -> { Path temp = Files.createTempFile(UUID.randomUUID().toString(), ".tmp"); try(OutputStream fout = Files.newOutputStream(temp)){ JaxbUtil.marshalWithNoValidation(config, fout); } Files.copy(temp, path,StandardCopyOption.REPLACE_EXISTING); return null; }); } }
public static String marshalToStringNoValidation(Object object) { return IOCallback.execute(() -> { try (OutputStream out = new ByteArrayOutputStream()) { marshalWithNoValidation(object, out); return out.toString(); } }); }
public static String marshalToStringNoValidation(Object object) { return IOCallback.execute(() -> { try (OutputStream out = new ByteArrayOutputStream()) { marshalWithNoValidation(object, out); return out.toString(); } }); }
static CliResult writeToOutputFile(Config config, Path outputPath) throws IOException { System.out.printf("Saving config to %s", outputPath); System.out.println(); JaxbUtil.marshalWithNoValidation(config, System.out); System.out.println(); try (OutputStream outputStream = Files.newOutputStream(outputPath)) { JaxbUtil.marshal(config, outputStream); System.out.printf("Saved config to %s", outputPath); System.out.println(); return new CliResult(0, false, config); } catch (ConstraintViolationException validationException) { validationException.getConstraintViolations() .stream() .map(cv -> "Warning: " + cv.getMessage() + " on property " + cv.getPropertyPath()) .forEach(System.err::println); Files.write(outputPath, JaxbUtil.marshalToStringNoValidation(config).getBytes()); System.out.printf("Saved config to %s", outputPath); System.out.println(); return new CliResult(2, false, config); } }
public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute(() -> { Marshaller marshaller = MarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); }
public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute(() -> { Marshaller marshaller = MarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); }