Search in sources :

Example 91 with FileWriter

use of java.io.FileWriter in project VitamioBundle by yixia.

the class Vitamio method extractLibs.

private static boolean extractLibs(Context ctx, int rawID) {
    long begin = System.currentTimeMillis();
    final int version = ContextUtils.getVersionCode(ctx);
    Log.d("loadLibs start " + version);
    File lock = new File(getLibraryPath() + LIBS_LOCK);
    if (lock.exists())
        lock.delete();
    String libPath = copyCompressedLib(ctx, rawID, "libarm.so");
    Log.d("copyCompressedLib time: " + (System.currentTimeMillis() - begin) / 1000.0);
    boolean inited = native_initializeLibs(libPath, getLibraryPath(), String.valueOf(Vitamio.getVitamioType()));
    new File(libPath).delete();
    FileWriter fw = null;
    try {
        lock.createNewFile();
        fw = new FileWriter(lock);
        fw.write(String.valueOf(version));
        return true;
    } catch (IOException e) {
        Log.e("Error creating lock file", e);
    } finally {
        Log.d("initializeNativeLibs: " + inited);
        Log.d("loadLibs time: " + (System.currentTimeMillis() - begin) / 1000.0);
        IOUtils.closeSilently(fw);
    }
    return false;
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 92 with FileWriter

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

the class BluetoothService method writeIncomingConnectionState.

/** @hide */
public void writeIncomingConnectionState(String address, Pair<Integer, String> data) {
    synchronized (mIncomingConnections) {
        mIncomingConnections.put(address, data);
        truncateIncomingConnectionFile();
        BufferedWriter out = null;
        StringBuilder value = new StringBuilder();
        try {
            out = new BufferedWriter(new FileWriter(INCOMING_CONNECTION_FILE, true));
            for (String devAddress : mIncomingConnections.keySet()) {
                Pair<Integer, String> val = mIncomingConnections.get(devAddress);
                value.append(devAddress);
                value.append(",");
                value.append(val.first.toString());
                value.append(",");
                value.append(val.second);
                value.append("\n");
            }
            out.write(value.toString());
        } catch (FileNotFoundException e) {
            log("FileNotFoundException: writeIncomingConnectionState" + e.toString());
        } catch (IOException e) {
            log("IOException: writeIncomingConnectionState" + e.toString());
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                // Ignore
                }
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 93 with FileWriter

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

the class BluetoothService method writeDockPin.

private synchronized boolean writeDockPin() {
    BufferedWriter out = null;
    try {
        out = new BufferedWriter(new FileWriter(DOCK_PIN_PATH));
        // Generate a random 4 digit pin between 0000 and 9999
        // This is not truly random but good enough for our purposes.
        int pin = (int) Math.floor(Math.random() * 10000);
        mDockPin = String.format("%04d", pin);
        out.write(mDockPin);
        return true;
    } catch (FileNotFoundException e) {
        Log.e(TAG, "FileNotFoundException while trying to write dock pairing pin");
    } catch (IOException e) {
        Log.e(TAG, "IOException while while trying to write dock pairing pin");
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
    mDockPin = null;
    return false;
}
Also used : FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 94 with FileWriter

use of java.io.FileWriter in project mysql_perf_analyzer by yahoo.

the class MyPerfConfiguration method store.

/**
	 * Make the configuration permanent 
	 * @param ctx
	 * @return
	 */
public synchronized boolean store(MyPerfContext ctx) {
    File cfgFile = new File(this.myperfConfigPath);
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(new FileWriter(cfgFile));
        pw.println("metricsScannerUser=" + this.metricsScannerUser);
        pw.println("adminEmail=" + this.adminEmail);
        pw.println("alertNotificationEmails=" + this.alertNotificationEmails);
        pw.println("scannerIntervalSeconds=" + this.scannerIntervalSeconds);
        pw.println("alertScanIntervalSeconds=" + this.alertScanIntervalSeconds);
        pw.println("recordRententionDays=" + this.recordRententionDays);
        pw.println("scannerThreadCount=" + this.scannerThreadCount);
        pw.println("reuseMonUserConnction=" + (reuseMonUserConnction ? "y" : "n"));
        pw.println("metricsDbType=" + this.metricsDbType);
        if (this.metricsDbHost != null && !this.metricsDbHost.isEmpty())
            pw.println("metricsDbHost=" + this.metricsDbHost);
        if (this.metricsDbPort > 0)
            pw.println("metricsDbPort=" + this.metricsDbPort);
        if (this.metricsDbName != null && !this.metricsDbName.isEmpty())
            pw.println("metricsDbName=" + this.metricsDbName);
        if (this.metricsDbUserName != null && !this.metricsDbUserName.isEmpty())
            pw.println("metricsDbUserName=" + this.metricsDbUserName);
        if (this.metricsDbPassword != null && !this.metricsDbPassword.isEmpty())
            pw.println("metricsDbPassword=" + ctx.getMetaDb().enc(this.metricsDbPassword));
        if (this.hipchatUrl != null && !this.hipchatUrl.isEmpty())
            pw.println("hipchatUrl=" + this.hipchatUrl);
        if (this.hipchatAuthToken != null && !this.hipchatAuthToken.isEmpty())
            pw.println("hipchatAuthToken=" + ctx.getMetaDb().enc(this.hipchatAuthToken));
        return true;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Failed to store configurations to file " + this.myperfConfigPath, ex);
    } finally {
        if (pw != null) {
            try {
                pw.flush();
                pw.close();
            } catch (Exception fex) {
            }
        }
    }
    return false;
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 95 with FileWriter

use of java.io.FileWriter in project mysql_perf_analyzer by yahoo.

the class SNMPSettings method store.

public synchronized boolean store() {
    File cfgFile = new File(this.myperfSnmpConfigPath);
    if (!cfgFile.exists()) {
        logger.log(Level.INFO, "There is no customized snmp configuration, create one.");
    }
    Writer pw = null;
    try {
        pw = new FileWriter(cfgFile);
        return this.writeToJson(pw);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Failed to store configurations to file " + this.myperfSnmpConfigPath, ex);
    } finally {
        if (pw != null) {
            try {
                pw.flush();
                pw.close();
            } catch (Exception fex) {
            }
        }
    }
    return false;
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

FileWriter (java.io.FileWriter)1994 File (java.io.File)1195 IOException (java.io.IOException)866 BufferedWriter (java.io.BufferedWriter)798 PrintWriter (java.io.PrintWriter)329 Test (org.junit.Test)243 Writer (java.io.Writer)181 FileReader (java.io.FileReader)148 BufferedReader (java.io.BufferedReader)128 ArrayList (java.util.ArrayList)121 FileNotFoundException (java.io.FileNotFoundException)78 Date (java.util.Date)68 FileOutputStream (java.io.FileOutputStream)65 Properties (java.util.Properties)65 HashMap (java.util.HashMap)61 FileInputStream (java.io.FileInputStream)54 StringWriter (java.io.StringWriter)51 Path (org.apache.hadoop.fs.Path)50 Map (java.util.Map)42 InputStreamReader (java.io.InputStreamReader)34