Example usage for java.nio.channels Channels newWriter

List of usage examples for java.nio.channels Channels newWriter

Introduction

In this page you can find the example usage for java.nio.channels Channels newWriter.

Prototype

public static Writer newWriter(WritableByteChannel ch, Charset charset) 

Source Link

Document

Constructs a writer that encodes characters according to the given charset and writes the resulting bytes to the given channel.

Usage

From source file:com.streak.logging.analysis.AnalysisUtility.java

public static void writeSchema(FileService fileService, String bucketName, String schemaKey,
        List<String> fieldNames, List<String> fieldTypes, List<BigqueryFieldExporter> exporters)
        throws IOException, FileNotFoundException, FinalizationException, LockException {
    GSFileOptionsBuilder schemaOptionsBuilder = new GSFileOptionsBuilder().setBucket(bucketName)
            .setKey(createSchemaFilename(schemaKey)).setAcl("project-private");
    AppEngineFile schemaFile = fileService.createNewGSFile(schemaOptionsBuilder.build());

    FileWriteChannel schemaChannel = fileService.openWriteChannel(schemaFile, true);
    PrintWriter schemaWriter = new PrintWriter(Channels.newWriter(schemaChannel, "UTF8"));

    JSONArray fields = new JSONArray();

    for (int i = 0; i < fieldNames.size(); i++) {
        try {/*from   w w  w.  j  av a  2s.c o  m*/
            JSONObject obj = new JSONObject();
            obj.put("name", fieldNames.get(i));
            obj.put("type", fieldTypes.get(i));

            BigqueryFieldExporter exp = exporters.get(i);
            if (exp instanceof BigqueryRecordFieldExporter) {
                obj.put("mode", "repeated");
                obj.put("fields", ((BigqueryRecordFieldExporter) exp).getRecordFields());
            } else {
                obj.put("mode", "nullable");
            }

            fields.put(obj);
        } catch (JSONException e) {
            log.severe("This should not happen!");
        }
    }

    schemaWriter.print(fields.toString());
    schemaWriter.close();

    schemaChannel.closeFinally();
}

From source file:com.spectralogic.ds3client.helpers.channels.WindowedSeekableByteChannel_Test.java

private static void writeToChannel(final String string, final SeekableByteChannel channel) throws IOException {
    final Writer writer = Channels.newWriter(channel, "UTF-8");
    writer.write(string);/*from  www .  j  a  v  a  2s.c o m*/
    writer.flush();
}

From source file:org.zaproxy.zap.extension.exportreport.Export.ReportExport.java

private static File write(String path, String str, Boolean append) throws Exception {
    File f = new File(path);

    try (Writer writer = Channels.newWriter(new FileOutputStream(f.getAbsoluteFile(), append).getChannel(),
            Utils.utf8)) {//from   ww  w .  ja  v  a2s .  c o m
        writer.append(str);
    }
    return f;
}

From source file:org.apache.beam.sdk.io.LocalFileSystemTest.java

private void createFileWithContent(Path path, String content) throws Exception {
    try (Writer writer = Channels.newWriter(
            localFileSystem.create(LocalResourceId.fromPath(path, false /* isDirectory */),
                    StandardCreateOptions.builder().setMimeType(MimeTypes.TEXT).build()),
            StandardCharsets.UTF_8.name())) {
        writer.write(content);/*from   ww  w  . j a v a2s.  c  o  m*/
    }
}