private char[] toCharArray(File file) throws IOException { try (FileInputStream is = new FileInputStream(file)) { return toCharArray(is); } }
private char[] toCharArray(InputStream is) throws IOException { try (Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { return toCharArray(reader); } }
public FileDescriptorSource addProtoFile(String name, InputStream contents) throws IOException { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } if (contents == null) { throw new IllegalArgumentException("contents cannot be null"); } // discard the leading slash String path = name.startsWith("/") ? name.substring(1) : name; descriptors.put(path, toCharArray(contents)); return this; }
public FileDescriptorSource addProtoFile(String name, Reader contents) throws IOException { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } if (contents == null) { throw new IllegalArgumentException("contents cannot be null"); } // discard the leading slash String path = name.startsWith("/") ? name.substring(1) : name; descriptors.put(path, toCharArray(contents)); return this; }
public FileDescriptorSource addProtoFile(String name, File protofile) throws IOException { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } if (protofile == null) { throw new IllegalArgumentException("protofile cannot be null"); } // discard the leading slash String path = name.startsWith("/") ? name.substring(1) : name; descriptors.put(path, toCharArray(protofile)); return this; }