use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project drill by apache.
the class JsonRecordWriter method init.
@Override
public void init(Map<String, String> writerOptions) throws IOException {
this.location = writerOptions.get("location");
this.prefix = writerOptions.get("prefix");
this.fieldDelimiter = writerOptions.get("separator");
this.extension = writerOptions.get("extension");
this.useExtendedOutput = Boolean.parseBoolean(writerOptions.get("extended"));
this.skipNullFields = Boolean.parseBoolean(writerOptions.get("skipnulls"));
final boolean uglify = Boolean.parseBoolean(writerOptions.get("uglify"));
Configuration conf = new Configuration();
conf.set(FileSystem.FS_DEFAULT_NAME_KEY, writerOptions.get(FileSystem.FS_DEFAULT_NAME_KEY));
this.fs = FileSystem.get(conf);
Path fileName = new Path(location, prefix + "_" + index + "." + extension);
try {
// json writer does not support partitions, so only one file can be created
// and thus only one location should be deleted in case of abort
// to ensure that our writer was the first to create output file,
// we create empty output file first and fail if file exists
cleanUpLocation = storageStrategy.createFileAndApply(fs, fileName);
// since empty output file will be overwritten (some file systems may restrict append option)
// we need to re-apply file permission
stream = fs.create(fileName);
storageStrategy.applyToFile(fs, fileName);
JsonGenerator generator = factory.createGenerator(stream).useDefaultPrettyPrinter();
if (uglify) {
generator = generator.setPrettyPrinter(new MinimalPrettyPrinter(LINE_FEED));
}
if (useExtendedOutput) {
gen = new ExtendedJsonOutput(generator);
} else {
gen = new BasicJsonOutput(generator);
}
logger.debug("Created file: {}", fileName);
} catch (IOException ex) {
logger.error("Unable to create file: " + fileName, ex);
throw ex;
}
}
use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project cas by apereo.
the class ReturnRestfulAttributeReleasePolicy method getAttributesInternal.
@Override
public Map<String, Object> getAttributesInternal(final Principal principal, final Map<String, Object> attributes, final RegisteredService service) {
try (StringWriter writer = new StringWriter()) {
MAPPER.writer(new MinimalPrettyPrinter()).writeValue(writer, attributes);
final HttpResponse response = HttpUtils.executePost(this.endpoint, writer.toString(), CollectionUtils.wrap("principal", principal.getId(), "service", service.getServiceId()));
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
return MAPPER.readValue(response.getEntity().getContent(), new TypeReference<Map<String, Object>>() {
});
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new HashMap<>(0);
}
use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project cas by apereo.
the class AbstractJacksonBackedStringSerializer method to.
@Override
@SneakyThrows
public void to(final File out, final T object) {
try (StringWriter writer = new StringWriter()) {
this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object);
if (isJsonFormat()) {
try (Writer fileWriter = Files.newBufferedWriter(out.toPath(), StandardCharsets.UTF_8)) {
final Stringify opt = this.prettyPrinter instanceof MinimalPrettyPrinter ? Stringify.PLAIN : Stringify.FORMATTED;
JsonValue.readHjson(writer.toString()).writeTo(fileWriter, opt);
fileWriter.flush();
}
} else {
FileUtils.write(out, writer.toString(), StandardCharsets.UTF_8);
}
}
}
use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project cas by apereo.
the class AbstractJacksonBackedStringSerializer method to.
@Override
@SneakyThrows
public void to(final Writer out, final T object) {
try (StringWriter writer = new StringWriter()) {
this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object);
if (isJsonFormat()) {
final Stringify opt = this.prettyPrinter instanceof MinimalPrettyPrinter ? Stringify.PLAIN : Stringify.FORMATTED;
JsonValue.readHjson(writer.toString()).writeTo(out, opt);
} else {
IOUtils.write(writer.toString(), out);
}
}
}
use of com.fasterxml.jackson.core.util.MinimalPrettyPrinter in project cas by apereo.
the class U2FRestResourceDeviceRepository method writeDevicesBackToResource.
@Override
protected void writeDevicesBackToResource(final List<U2FDeviceRegistration> list) {
try (StringWriter writer = new StringWriter()) {
final Map<String, List<U2FDeviceRegistration>> newDevices = new HashMap<>();
newDevices.put(MAP_KEY_SERVICES, list);
mapper.writer(new MinimalPrettyPrinter()).writeValue(writer, newDevices);
HttpUtils.executePost(restProperties.getUrl(), restProperties.getBasicAuthUsername(), restProperties.getBasicAuthPassword(), writer.toString());
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
Aggregations