2010-02-08 20:39:42 +00:00
|
|
|
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
|
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
|
|
|
|
package org.torproject.android;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
2010-03-18 03:15:20 +00:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
2010-02-08 20:39:42 +00:00
|
|
|
|
|
|
|
public class Utils {
|
|
|
|
|
|
|
|
|
2010-03-18 03:15:20 +00:00
|
|
|
public static String readString (InputStream stream)
|
|
|
|
{
|
|
|
|
String line = null;
|
|
|
|
|
|
|
|
StringBuffer out = new StringBuffer();
|
|
|
|
|
|
|
|
try {
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
|
|
|
|
|
|
|
while ((line = reader.readLine()) != null)
|
|
|
|
{
|
|
|
|
out.append(line);
|
|
|
|
out.append('\n');
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return out.toString();
|
|
|
|
|
|
|
|
}
|
2010-02-08 20:39:42 +00:00
|
|
|
/*
|
|
|
|
* Load the log file text
|
|
|
|
*/
|
|
|
|
public static String loadTextFile (String path)
|
|
|
|
{
|
|
|
|
String line = null;
|
|
|
|
|
|
|
|
StringBuffer out = new StringBuffer();
|
|
|
|
|
|
|
|
try {
|
|
|
|
BufferedReader reader = new BufferedReader((new FileReader(new File(path))));
|
|
|
|
|
|
|
|
while ((line = reader.readLine()) != null)
|
|
|
|
{
|
|
|
|
out.append(line);
|
|
|
|
out.append('\n');
|
|
|
|
|
|
|
|
}
|
2013-02-12 07:28:29 +00:00
|
|
|
|
|
|
|
reader.close();
|
2010-02-08 20:39:42 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return out.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the log file text
|
|
|
|
*/
|
|
|
|
public static boolean saveTextFile (String path, String contents)
|
|
|
|
{
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
FileWriter writer = new FileWriter( path, false );
|
|
|
|
writer.write( contents );
|
|
|
|
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
2010-09-09 20:39:52 +00:00
|
|
|
// Log.d(TAG, "error writing file: " + path, e);
|
2010-02-08 20:39:42 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|