| 18 | import java.util.List; |
| 19 | |
| 20 | public class Path { |
| 21 | |
| 22 | private static final String TAG = Path.class.getSimpleName(); |
| 23 | |
| 24 | private static File mkdir(File file) { |
| 25 | if (!file.exists()) file.mkdirs(); |
| 26 | return file; |
| 27 | } |
| 28 | |
| 29 | public static File download() { |
| 30 | return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); |
| 31 | } |
| 32 | |
| 33 | public static File root() { |
| 34 | return Environment.getExternalStorageDirectory(); |
| 35 | } |
| 36 | |
| 37 | public static File tv() { |
| 38 | return mkdir(new File(root() + File.separator + "TV")); |
| 39 | } |
| 40 | |
| 41 | public static File tv(String name) { |
| 42 | if (!name.startsWith(".")) name = "." + name; |
| 43 | return new File(tv(), name); |
| 44 | } |
| 45 | |
| 46 | public static String read(File file) { |
| 47 | try { |
| 48 | return new String(readToByte(file), StandardCharsets.UTF_8); |
| 49 | } catch (IOException e) { |
| 50 | return ""; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | public static String read(InputStream is) { |
| 55 | try { |
| 56 | return new String(readToByte(is), StandardCharsets.UTF_8); |
| 57 | } catch (IOException e) { |
| 58 | e.printStackTrace(); |
| 59 | return ""; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | private static byte[] readToByte(File file) throws IOException { |
| 64 | try (FileInputStream is = new FileInputStream(file)) { |
| 65 | return readToByte(is); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | private static byte[] readToByte(InputStream is) throws IOException { |
| 70 | try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
| 71 | int read; |
| 72 | byte[] buffer = new byte[16384]; |
| 73 | while ((read = is.read(buffer)) != -1) bos.write(buffer, 0, read); |
| 74 | return bos.toByteArray(); |
| 75 | } |
| 76 | } |
| 77 |
nothing calls this directly
no outgoing calls
no test coverage detected