Search in sources :

Example 66 with BufferedWriter

use of java.io.BufferedWriter in project screenbird by adamhub.

the class FileUtilTest method createFile.

public void createFile(String name) throws IOException {
    properties = folder.newFile(name);
    BufferedWriter out = new BufferedWriter(new FileWriter(properties));
    out.write("this simulates a jpg file");
    out.close();
}
Also used : FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 67 with BufferedWriter

use of java.io.BufferedWriter in project archaius by Netflix.

the class DynamicFileConfigurationTest method createConfigFile.

static File createConfigFile(String prefix) throws Exception {
    configFile = File.createTempFile(prefix, ".properties");
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), "UTF-8"));
    writer.write("dprops1=123456789");
    writer.newLine();
    writer.write("dprops2=79.98");
    writer.newLine();
    // this property should fail validation but should not affect update of other properties
    writer.write("abc=-2");
    writer.newLine();
    writer.close();
    System.err.println(configFile.getPath() + " created");
    return configFile;
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 68 with BufferedWriter

use of java.io.BufferedWriter in project archaius by Netflix.

the class DynamicFileConfigurationTest method modifyConfigFile.

static void modifyConfigFile() {
    new Thread() {

        public void run() {
            try {
                BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), "UTF-8"));
                // this property should fail validation but should not affect update of other properties
                writer.write("abc=-8");
                writer.newLine();
                writer.write("dprops1=" + String.valueOf(Long.MIN_VALUE));
                writer.newLine();
                writer.write("dprops2=" + String.valueOf(Double.MAX_VALUE));
                writer.newLine();
                writer.close();
                System.err.println(configFile.getPath() + " modified");
            } catch (Exception e) {
                e.printStackTrace();
                fail("Unexpected exception");
            }
        }
    }.start();
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ValidationException(com.netflix.config.validation.ValidationException) BufferedWriter(java.io.BufferedWriter)

Example 69 with BufferedWriter

use of java.io.BufferedWriter in project mounts2sd by SpazeDog.

the class FragmentTabLog method saveLogEntry.

public void saveLogEntry() {
    File sdcardPath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getParent() + "/Mounts2SD");
    File logFile = new File(sdcardPath, "log.txt");
    sdcardPath.mkdirs();
    try {
        BufferedWriter output = new BufferedWriter(new FileWriter(logFile.getAbsolutePath(), false));
        for (int i = 0; i < oLogEntry.length; i++) {
            output.write(oLogEntry[i] + "\r\n");
        }
        output.close();
        Toast.makeText(getActivity(), String.format(getResources().getString(R.string.toast_log_copied), logFile.getAbsolutePath()), Toast.LENGTH_LONG).show();
    } catch (Throwable e) {
        Toast.makeText(getActivity(), getResources().getString(R.string.toast_log_unsuccessful), Toast.LENGTH_LONG).show();
    }
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 70 with BufferedWriter

use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.

the class WindowManagerService method viewServerListWindows.

/**
     * Lists all availble windows in the system. The listing is written in the
     * specified Socket's output stream with the following syntax:
     * windowHashCodeInHexadecimal windowName
     * Each line of the ouput represents a different window.
     *
     * @param client The remote client to send the listing to.
     * @return False if an error occured, true otherwise.
     */
boolean viewServerListWindows(Socket client) {
    if (isSystemSecure()) {
        return false;
    }
    boolean result = true;
    WindowList windows = new WindowList();
    synchronized (mWindowMap) {
        //noinspection unchecked
        final int numDisplays = mDisplayContents.size();
        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
            windows.addAll(displayContent.getWindowList());
        }
    }
    BufferedWriter out = null;
    // Any uncaught exception will crash the system process
    try {
        OutputStream clientStream = client.getOutputStream();
        out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
        final int count = windows.size();
        for (int i = 0; i < count; i++) {
            final WindowState w = windows.get(i);
            out.write(Integer.toHexString(System.identityHashCode(w)));
            out.write(' ');
            out.append(w.mAttrs.getTitle());
            out.write('\n');
        }
        out.write("DONE.\n");
        out.flush();
    } catch (Exception e) {
        result = false;
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                result = false;
            }
        }
    }
    return result;
}
Also used : OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Point(android.graphics.Point) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchElementException(java.util.NoSuchElementException) BufferedWriter(java.io.BufferedWriter)

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