mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-03 06:12:55 +00:00
Add the ability to import an eSpeak dictionary file from the SD card.
This commit is contained in:
@@ -26,14 +26,30 @@ import java.io.InputStream;
|
||||
|
||||
public class FileUtils {
|
||||
public static String read(File file) throws IOException {
|
||||
return read(new FileInputStream(file), (int)file.length());
|
||||
return readByteArray(new FileInputStream(file), (int)file.length()).toString();
|
||||
}
|
||||
|
||||
public static String read(InputStream stream) throws IOException {
|
||||
return read(stream, stream.available());
|
||||
return readByteArray(stream, stream.available()).toString();
|
||||
}
|
||||
|
||||
public static String read(InputStream stream, int length) throws IOException {
|
||||
return readByteArray(stream, length).toString();
|
||||
}
|
||||
|
||||
public static byte[] readBinary(File file) throws IOException {
|
||||
return readByteArray(new FileInputStream(file), (int)file.length()).toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] readBinary(InputStream stream) throws IOException {
|
||||
return readByteArray(stream, stream.available()).toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] readBinary(InputStream stream, int length) throws IOException {
|
||||
return readByteArray(stream, length).toByteArray();
|
||||
}
|
||||
|
||||
private static ByteArrayOutputStream readByteArray(InputStream stream, int length) throws IOException {
|
||||
ByteArrayOutputStream content = new ByteArrayOutputStream(length);
|
||||
int c = stream.read();
|
||||
while (c != -1)
|
||||
@@ -41,13 +57,17 @@ public class FileUtils {
|
||||
content.write((byte)c);
|
||||
c = stream.read();
|
||||
}
|
||||
return content.toString();
|
||||
return content;
|
||||
}
|
||||
|
||||
public static void write(File outputFile, String contents) throws IOException {
|
||||
write(outputFile, contents.getBytes());
|
||||
}
|
||||
|
||||
public static void write(File outputFile, byte[] contents) throws IOException {
|
||||
FileOutputStream outputStream = new FileOutputStream(outputFile);
|
||||
try {
|
||||
outputStream.write(contents.getBytes(), 0, contents.length());
|
||||
outputStream.write(contents, 0, contents.length);
|
||||
} finally {
|
||||
outputStream.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user