Search in sources :

Example 1 with BufferedWriter

use of java.io.BufferedWriter in project jetty.project by eclipse.

the class FileSystemResourceTest method testInputStream.

@Test
public void testInputStream() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path file = dir.resolve("foo");
    String content = "Foo is here";
    try (StringReader reader = new StringReader(content);
        BufferedWriter writer = Files.newBufferedWriter(file)) {
        IO.copy(reader, writer);
    }
    try (Resource base = newResource(dir.toFile())) {
        Resource foo = base.addPath("foo");
        try (InputStream stream = foo.getInputStream();
            InputStreamReader reader = new InputStreamReader(stream);
            StringWriter writer = new StringWriter()) {
            IO.copy(reader, writer);
            assertThat("Stream", writer.toString(), is(content));
        }
    }
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) StringReader(java.io.StringReader) Matchers.containsString(org.hamcrest.Matchers.containsString) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 2 with BufferedWriter

use of java.io.BufferedWriter in project jetty.project by eclipse.

the class FileSystemResourceTest method testLength.

@Test
public void testLength() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path file = dir.resolve("foo");
    try (StringReader reader = new StringReader("foo");
        BufferedWriter writer = Files.newBufferedWriter(file)) {
        IO.copy(reader, writer);
    }
    long expected = Files.size(file);
    try (Resource base = newResource(dir.toFile())) {
        Resource res = base.addPath("foo");
        assertThat("foo.length", res.length(), is(expected));
    }
}
Also used : Path(java.nio.file.Path) StringReader(java.io.StringReader) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 3 with BufferedWriter

use of java.io.BufferedWriter in project vert.x by eclipse.

the class HttpTest method setupFile.

protected File setupFile(String fileName, String content) throws Exception {
    File file = new File(testDir, fileName);
    if (file.exists()) {
        file.delete();
    }
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
    out.write(content);
    out.close();
    return file;
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 4 with BufferedWriter

use of java.io.BufferedWriter in project jetty.project by eclipse.

the class PropertyUserStoreTest method initUsersText.

private File initUsersText() throws Exception {
    Path dir = testdir.getPath().toRealPath();
    FS.ensureDirExists(dir.toFile());
    File users = dir.resolve("users.txt").toFile();
    try (Writer writer = new BufferedWriter(new FileWriter(users))) {
        writer.append("tom: tom, roleA\n");
        writer.append("dick: dick, roleB\n");
        writer.append("harry: harry, roleA, roleB\n");
    }
    return users;
}
Also used : Path(java.nio.file.Path) FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 5 with BufferedWriter

use of java.io.BufferedWriter in project jetty.project by eclipse.

the class ModuleGraphWriter method write.

public void write(Modules modules, Path outputFile) throws IOException {
    try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
        PrintWriter out = new PrintWriter(writer)) {
        writeHeaderMessage(out, outputFile);
        out.println();
        out.println("digraph modules {");
        // Node Style
        out.println("  node [color=gray, style=filled, shape=rectangle];");
        out.println("  node [fontname=\"Verdana\", size=\"20,20\"];");
        // Graph Style
        out.println("  graph [");
        out.println("    concentrate=false,");
        out.println("    fontname=\"Verdana\",");
        out.println("    fontsize = 20,");
        out.println("    rankdir = LR,");
        out.println("    ranksep = 1.5,");
        out.println("    nodesep = .5,");
        out.println("    style = bold,");
        out.println("    labeljust = l,");
        out.println("    label = \"Jetty Modules\",");
        out.println("    ssize = \"20,40\"");
        out.println("  ];");
        List<Module> enabled = modules.getEnabled();
        // Module Nodes
        writeModules(out, modules, enabled);
        // Module Relationships
        writeRelationships(out, modules, enabled);
        out.println("}");
        out.println();
    }
}
Also used : BufferedWriter(java.io.BufferedWriter) PrintWriter(java.io.PrintWriter)

Aggregations

BufferedWriter (java.io.BufferedWriter)4214 FileWriter (java.io.FileWriter)2181 File (java.io.File)1879 IOException (java.io.IOException)1847 OutputStreamWriter (java.io.OutputStreamWriter)1344 BufferedReader (java.io.BufferedReader)747 FileOutputStream (java.io.FileOutputStream)656 ArrayList (java.util.ArrayList)386 FileReader (java.io.FileReader)376 InputStreamReader (java.io.InputStreamReader)349 PrintWriter (java.io.PrintWriter)324 Writer (java.io.Writer)324 Test (org.junit.Test)286 FileNotFoundException (java.io.FileNotFoundException)217 OutputStream (java.io.OutputStream)213 HashMap (java.util.HashMap)200 Path (java.nio.file.Path)177 InputStream (java.io.InputStream)171 FileInputStream (java.io.FileInputStream)158 StringWriter (java.io.StringWriter)143