Browse Source

FileUtils: Set the initial size of the ByteArrayOutputStream buffer.

master
Reece H. Dunn 11 years ago
parent
commit
dea3ee743f

+ 1
- 1
android/src/com/reecedunn/espeak/CheckVoiceData.java View File

public static boolean canUpgradeResources(Context context) { public static boolean canUpgradeResources(Context context) {
try { try {
final String version = FileUtils.read(context.getResources().openRawResource(R.raw.espeakdata_version)); final String version = FileUtils.read(context.getResources().openRawResource(R.raw.espeakdata_version));
final String installedVersion = FileUtils.read(new FileInputStream(new File(getDataPath(context), "version")));
final String installedVersion = FileUtils.read(new File(getDataPath(context), "version"));
return !version.equals(installedVersion); return !version.equals(installedVersion);
} catch (Exception e) { } catch (Exception e) {
return false; return false;

+ 10
- 1
android/src/com/reecedunn/espeak/FileUtils.java View File



import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;


public class FileUtils { public class FileUtils {
public static String read(File file) throws IOException {
return read(new FileInputStream(file), (int)file.length());
}

public static String read(InputStream stream) throws IOException { public static String read(InputStream stream) throws IOException {
ByteArrayOutputStream content = new ByteArrayOutputStream();
return read(stream, stream.available());
}

public static String read(InputStream stream, int length) throws IOException {
ByteArrayOutputStream content = new ByteArrayOutputStream(length);
int c = stream.read(); int c = stream.read();
while (c != -1) while (c != -1)
{ {

Loading…
Cancel
Save