use of java.io.OutputStreamWriter in project camel by apache.
the class CamelSalesforceMojo method processDescription.
void processDescription(File pkgDir, SObjectDescription description, GeneratorUtility utility, String generatedDate) throws IOException {
// generate a source file for SObject
final VelocityContext context = new VelocityContext();
context.put("packageName", packageName);
context.put("utility", utility);
context.put("esc", StringEscapeUtils.class);
context.put("desc", description);
context.put("generatedDate", generatedDate);
context.put("useStringsForPicklists", useStringsForPicklists);
final String pojoFileName = description.getName() + JAVA_EXT;
final File pojoFile = new File(pkgDir, pojoFileName);
try (final Writer writer = new OutputStreamWriter(new FileOutputStream(pojoFile), StandardCharsets.UTF_8)) {
final Template pojoTemplate = engine.getTemplate(SOBJECT_POJO_VM, UTF_8);
pojoTemplate.merge(context, writer);
}
if (useOptionals) {
final String optionalFileName = description.getName() + "Optional" + JAVA_EXT;
final File optionalFile = new File(pkgDir, optionalFileName);
try (final Writer writer = new OutputStreamWriter(new FileOutputStream(optionalFile), StandardCharsets.UTF_8)) {
final Template optionalTemplate = engine.getTemplate(SOBJECT_POJO_OPTIONAL_VM, UTF_8);
optionalTemplate.merge(context, writer);
}
}
// write required Enumerations for any picklists
for (SObjectField field : description.getFields()) {
if (utility.isPicklist(field) || utility.isMultiSelectPicklist(field)) {
final String enumName = description.getName() + "_" + utility.enumTypeName(field.getName());
final String enumFileName = enumName + JAVA_EXT;
final File enumFile = new File(pkgDir, enumFileName);
context.put("field", field);
context.put("enumName", enumName);
final Template enumTemplate = engine.getTemplate(SOBJECT_PICKLIST_VM, UTF_8);
try (final Writer writer = new OutputStreamWriter(new FileOutputStream(enumFile), StandardCharsets.UTF_8)) {
enumTemplate.merge(context, writer);
}
}
}
// write the QueryRecords class
final String queryRecordsFileName = "QueryRecords" + description.getName() + JAVA_EXT;
final File queryRecordsFile = new File(pkgDir, queryRecordsFileName);
final Template queryTemplate = engine.getTemplate(SOBJECT_QUERY_RECORDS_VM, UTF_8);
try (final Writer writer = new OutputStreamWriter(new FileOutputStream(queryRecordsFile), StandardCharsets.UTF_8)) {
queryTemplate.merge(context, writer);
}
if (useOptionals) {
// write the QueryRecords Optional class
final String queryRecordsOptionalFileName = "QueryRecords" + description.getName() + "Optional" + JAVA_EXT;
final File queryRecordsOptionalFile = new File(pkgDir, queryRecordsOptionalFileName);
final Template queryRecordsOptionalTemplate = engine.getTemplate(SOBJECT_QUERY_RECORDS_OPTIONAL_VM, UTF_8);
try (final Writer writer = new OutputStreamWriter(new FileOutputStream(queryRecordsOptionalFile), StandardCharsets.UTF_8)) {
queryRecordsOptionalTemplate.merge(context, writer);
}
}
}
use of java.io.OutputStreamWriter in project storm-json by rapportive-oss.
the class SimpleJSONSerializer method serialize.
/**
* Serialise a JSON object or array to the stream.
*
* @throws IllegalArgumentException if <tt>object</tt> is not a JSON
* object or array
* @throws IOException if there is an error writing to the stream.
*/
@Override
public void serialize(Object object, DataOutputStream stream) throws IOException {
final Writer writer = new OutputStreamWriter(stream, ENCODING);
if (object instanceof JSONObject) {
((JSONObject) object).writeJSONString(writer);
} else if (object instanceof JSONArray) {
((JSONArray) object).writeJSONString(writer);
} else {
throw new IllegalArgumentException("Unexpected class " + object.getClass().getCanonicalName());
}
writer.flush();
}
use of java.io.OutputStreamWriter in project retrofit by square.
the class GsonRequestBodyConverter method convert.
@Override
public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
use of java.io.OutputStreamWriter in project flink by apache.
the class CsvOutputFormat method open.
// --------------------------------------------------------------------------------------------
@Override
public void open(int taskNumber, int numTasks) throws IOException {
super.open(taskNumber, numTasks);
this.wrt = this.charsetName == null ? new OutputStreamWriter(new BufferedOutputStream(this.stream, 4096)) : new OutputStreamWriter(new BufferedOutputStream(this.stream, 4096), this.charsetName);
}
use of java.io.OutputStreamWriter in project cube-sdk by liaohuqiu.
the class PostRequestSender method send.
@Override
public void send() throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(mHttpURLConnection.getOutputStream());
writer.write(mRequestData.getPostString());
writer.flush();
}
Aggregations