eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileUtils.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2012-2013 Reece H. Dunn
  3. * Copyright (C) 2009 The Android Open Source Project
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.reecedunn.espeak;
  18. import java.io.ByteArrayOutputStream;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.io.FileOutputStream;
  22. import java.io.IOException;
  23. import java.io.InputStream;
  24. public class FileUtils {
  25. public static String read(File file) throws IOException {
  26. return read(new FileInputStream(file), (int)file.length());
  27. }
  28. public static String read(InputStream stream) throws IOException {
  29. return read(stream, stream.available());
  30. }
  31. public static String read(InputStream stream, int length) throws IOException {
  32. ByteArrayOutputStream content = new ByteArrayOutputStream(length);
  33. int c = stream.read();
  34. while (c != -1)
  35. {
  36. content.write((byte)c);
  37. c = stream.read();
  38. }
  39. return content.toString();
  40. }
  41. public static void write(File outputFile, String contents) throws IOException {
  42. FileOutputStream outputStream = new FileOutputStream(outputFile);
  43. try {
  44. outputStream.write(contents.getBytes(), 0, contents.length());
  45. } finally {
  46. outputStream.close();
  47. }
  48. chmod(outputFile);
  49. }
  50. public static void chmod(File file) {
  51. try {
  52. Runtime.getRuntime().exec("/system/bin/chmod 755 " + file.getAbsolutePath());
  53. } catch (IOException e) {
  54. e.printStackTrace();
  55. }
  56. }
  57. public static void rmdir(File directory) {
  58. if (!directory.exists() || !directory.isDirectory()) {
  59. return;
  60. }
  61. for (File child : directory.listFiles()) {
  62. if (child.isDirectory()) {
  63. rmdir(child);
  64. }
  65. child.delete();
  66. }
  67. }
  68. }