I have a file that contains some amount of plain text at the start followed by binary content at the end. The size of the binary content is determined by some one of the plain text lines I read. I was using a BufferedReader to read the individual lines, however it exposes no methods to refer to read a byte array. The readUTF for a DataInputStream doesnt read all the way to the end of the line, and the readLine method is deprecated.
Using the underlying FileInputStream to read returns empty byte arrays. Any suggestions on how to go about this?
The code is pretty ordinary
private DOTDataInfo parseFile(InputStream stream) throws IOException{ DOTDataInfo info = new DOTDataInfo(); BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); int binSize = 0; String line; while((line = reader.readLine()) != null){ if(line.length() == 0) break; DOTProperty prop = parseProperty(line); info.getProperties().add(prop); if(prop.getName().equals("ContentSize")) binSize = Integer.parseInt(prop.getValue()); } byte[] content = new byte[binSize]; stream.read(content); //Its all empty now. If I use a DataInputStream instead, its got the values from the file return info; }