Search in sources :

Example 91 with PrintStream

use of java.io.PrintStream in project buck by facebook.

the class DirtyPrintStreamDecoratorTest method testPrintlnFloat.

@Test
public void testPrintlnFloat() {
    PrintStream delegate = createMock(PrintStream.class);
    float value = 2.718f;
    delegate.println(value);
    delegate.close();
    EasyMock.expectLastCall().anyTimes();
    replay(delegate);
    try (DirtyPrintStreamDecorator dirtyPrintStream = new DirtyPrintStreamDecorator(delegate)) {
        dirtyPrintStream.println(value);
        verify(delegate);
        assertTrue(dirtyPrintStream.isDirty());
    }
}
Also used : PrintStream(java.io.PrintStream) Test(org.junit.Test)

Example 92 with PrintStream

use of java.io.PrintStream in project stetho by facebook.

the class APODDumperPlugin method dump.

@Override
public void dump(DumperContext dumpContext) throws DumpException {
    PrintStream writer = dumpContext.getStdout();
    Iterator<String> argsIter = dumpContext.getArgsAsList().iterator();
    String command = ArgsHelper.nextOptionalArg(argsIter, null);
    if (CMD_LIST.equalsIgnoreCase(command)) {
        doList(writer);
    } else if (CMD_DELETE.equalsIgnoreCase(command)) {
        doRemove(writer, argsIter);
    } else if (CMD_CLEAR.equalsIgnoreCase(command)) {
        doClear(writer);
    } else if (CMD_REFRESH.equalsIgnoreCase(command)) {
        doRefresh(writer);
    } else {
        usage(writer);
        if (command != null) {
            throw new DumpUsageException("Unknown command: " + command);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) DumpUsageException(com.facebook.stetho.dumpapp.DumpUsageException)

Example 93 with PrintStream

use of java.io.PrintStream in project stetho by facebook.

the class HprofDumperPlugin method dump.

@Override
public void dump(DumperContext dumpContext) throws DumpException {
    final PrintStream output = dumpContext.getStdout();
    Iterator<String> argsIter = dumpContext.getArgsAsList().iterator();
    String outputPath = argsIter.hasNext() ? argsIter.next() : null;
    if (outputPath == null) {
        usage(output);
    } else {
        if ("-".equals(outputPath)) {
            handlePipeOutput(output);
        } else {
            File outputFile = new File(outputPath);
            if (!outputFile.isAbsolute()) {
                outputFile = mContext.getFileStreamPath(outputPath);
            }
            writeHprof(outputFile);
            output.println("Wrote to " + outputFile);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) File(java.io.File)

Example 94 with PrintStream

use of java.io.PrintStream in project gocd by gocd.

the class BuildOutputLogger method consumeLine.

public synchronized void consumeLine(String line) {
    if (data == null) {
        throw new RuntimeException("No log file specified");
    }
    PrintStream out = null;
    try {
        out = new PrintStream(new FileOutputStream(data, true));
        out.println(line);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException)

Example 95 with PrintStream

use of java.io.PrintStream in project XobotOS by xamarin.

the class FileURLConnection method getDirectoryListing.

/**
     * Returns the directory listing of the file component as an input stream.
     *
     * @return the input stream of the directory listing
     */
private InputStream getDirectoryListing(File f) {
    String[] fileList = f.list();
    ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
    PrintStream out = new PrintStream(bytes);
    out.print("<title>Directory Listing</title>\n");
    out.print("<base href=\"file:");
    out.print(f.getPath().replace('\\', '/') + "/\"><h1>" + f.getPath() + "</h1>\n<hr>\n");
    int i;
    for (i = 0; i < fileList.length; i++) {
        out.print(fileList[i] + "<br>\n");
    }
    out.close();
    return new ByteArrayInputStream(bytes.toByteArray());
}
Also used : PrintStream(java.io.PrintStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

PrintStream (java.io.PrintStream)1828 ByteArrayOutputStream (java.io.ByteArrayOutputStream)805 Test (org.junit.Test)583 File (java.io.File)331 IOException (java.io.IOException)295 FileOutputStream (java.io.FileOutputStream)207 ArrayList (java.util.ArrayList)89 FileNotFoundException (java.io.FileNotFoundException)83 OutputStream (java.io.OutputStream)81 Before (org.junit.Before)66 BufferedReader (java.io.BufferedReader)53 BufferedOutputStream (java.io.BufferedOutputStream)49 Map (java.util.Map)49 Date (java.util.Date)46 Path (org.apache.hadoop.fs.Path)42 UnsupportedEncodingException (java.io.UnsupportedEncodingException)41 InputStreamReader (java.io.InputStreamReader)38 Matchers.anyString (org.mockito.Matchers.anyString)38 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)36 List (java.util.List)35