Search in sources :

Example 6 with OutputStreamWriter

use of java.io.OutputStreamWriter in project druid by druid-io.

the class NamespacedExtractorModuleTest method testListNamespaces.

@Test
public void testListNamespaces() throws Exception {
    final File tmpFile = temporaryFolder.newFile();
    try (OutputStreamWriter out = new FileWriter(tmpFile)) {
        out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
    }
    final URIExtractionNamespace namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())), new Period(0), null);
    try (CacheScheduler.Entry entry = scheduler.scheduleAndWait(namespace, 1_000)) {
        Assert.assertNotNull(entry);
        entry.awaitTotalUpdates(1);
        Assert.assertEquals(1, scheduler.getActiveEntries());
    }
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) FileWriter(java.io.FileWriter) Period(org.joda.time.Period) OutputStreamWriter(java.io.OutputStreamWriter) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) File(java.io.File) CacheScheduler(io.druid.server.lookup.namespace.cache.CacheScheduler) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) Test(org.junit.Test)

Example 7 with OutputStreamWriter

use of java.io.OutputStreamWriter in project druid by druid-io.

the class NamespacedExtractorModuleTest method testDeleteNamespaces.

//(timeout = 10_000)
@Test
public void testDeleteNamespaces() throws Exception {
    final File tmpFile = temporaryFolder.newFile();
    try (OutputStreamWriter out = new FileWriter(tmpFile)) {
        out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
    }
    final URIExtractionNamespace namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())), new Period(0), null);
    try (CacheScheduler.Entry entry = scheduler.scheduleAndWait(namespace, 1_000)) {
        Assert.assertNotNull(entry);
    }
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) FileWriter(java.io.FileWriter) Period(org.joda.time.Period) OutputStreamWriter(java.io.OutputStreamWriter) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) File(java.io.File) CacheScheduler(io.druid.server.lookup.namespace.cache.CacheScheduler) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) Test(org.junit.Test)

Example 8 with OutputStreamWriter

use of java.io.OutputStreamWriter in project druid by druid-io.

the class FileSmoosher method close.

@Override
public void close() throws IOException {
    //book keeping checks on created file.
    if (!completedFiles.isEmpty() || !filesInProcess.isEmpty()) {
        for (File file : completedFiles) {
            if (!file.delete()) {
                LOG.warn("Unable to delete file [%s]", file);
            }
        }
        for (File file : filesInProcess) {
            if (!file.delete()) {
                LOG.warn("Unable to delete file [%s]", file);
            }
        }
        throw new ISE("[%d] writers in progress and [%d] completed writers needs to be closed before closing smoosher.", filesInProcess.size(), completedFiles.size());
    }
    if (currOut != null) {
        currOut.close();
    }
    File metaFile = metaFile(baseDir);
    try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(metaFile), Charsets.UTF_8))) {
        out.write(String.format("v1,%d,%d", maxChunkSize, outFiles.size()));
        out.write("\n");
        for (Map.Entry<String, Metadata> entry : internalFiles.entrySet()) {
            final Metadata metadata = entry.getValue();
            out.write(joiner.join(entry.getKey(), metadata.getFileNum(), metadata.getStartOffset(), metadata.getEndOffset()));
            out.write("\n");
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ISE(io.druid.java.util.common.ISE) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Map(java.util.Map) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 9 with OutputStreamWriter

use of java.io.OutputStreamWriter in project che by eclipse.

the class CommitMessageWriter method writeTo.

/**
     * @see MessageBodyWriter#writeTo(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType,
     *      javax.ws.rs.core.MultivaluedMap, java.io.OutputStream)
     */
@Override
public void writeTo(Revision revision, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    Writer writer = new OutputStreamWriter(entityStream);
    writer.write('[');
    writer.write(revision.getBranch());
    writer.write(' ');
    writer.write(revision.getId());
    writer.write(']');
    writer.write(' ');
    writer.write(revision.getMessage());
    writer.write('\n');
    writer.flush();
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 10 with OutputStreamWriter

use of java.io.OutputStreamWriter in project che by eclipse.

the class RemoteListWriter method writeTo.

/**
     * @see MessageBodyWriter#writeTo(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType,
     *      javax.ws.rs.core.MultivaluedMap, java.io.OutputStream)
     */
@Override
public void writeTo(Iterable<Remote> remotes, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    Writer writer = new OutputStreamWriter(entityStream);
    for (Remote remote : remotes) {
        writer.write(remote.getName());
        String url = remote.getUrl();
        if (url != null) {
            writer.write(' ');
            writer.write(' ');
            writer.write(url);
        }
        writer.write('\n');
    }
    writer.flush();
}
Also used : Remote(org.eclipse.che.api.git.shared.Remote) OutputStreamWriter(java.io.OutputStreamWriter) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)3616 IOException (java.io.IOException)1453 FileOutputStream (java.io.FileOutputStream)1408 BufferedWriter (java.io.BufferedWriter)1320 Writer (java.io.Writer)939 File (java.io.File)912 PrintWriter (java.io.PrintWriter)589 InputStreamReader (java.io.InputStreamReader)510 OutputStream (java.io.OutputStream)507 BufferedReader (java.io.BufferedReader)426 ByteArrayOutputStream (java.io.ByteArrayOutputStream)373 InputStream (java.io.InputStream)255 URL (java.net.URL)242 HttpURLConnection (java.net.HttpURLConnection)208 FileNotFoundException (java.io.FileNotFoundException)207 Test (org.junit.Test)201 ArrayList (java.util.ArrayList)198 Path (org.apache.hadoop.fs.Path)194 UnsupportedEncodingException (java.io.UnsupportedEncodingException)169 FileInputStream (java.io.FileInputStream)167