| 797 | } |
| 798 | |
| 799 | @Override |
| 800 | public void close() throws IOException { |
| 801 | scanner.close(); |
| 802 | } |
| 803 | |
| 804 | } |
| 805 | private static class BinaryInput implements Input { |
| 806 | private final ReadableByteChannel channel; |
| 807 | private final ByteBuffer buffer; |
| 808 | private int bufferLength; |
| 809 | |
| 810 | public BinaryInput(ReadableByteChannel channel, ByteOrder byteOrder) throws IOException { |
| 811 | final byte[] END="end_header".getBytes("US-ASCII"); |
| 812 | byte[] endTest=new byte[END.length]; |
| 813 | |
| 814 | this.channel=channel; |
| 815 | buffer=ByteBuffer.allocate(8192).order(byteOrder); |
| 816 | bufferLength=0; |
| 817 | // skip header |
| 818 | int lineStart=0; |
| 819 | int read; |
| 820 | while (true) { |
| 821 | read=channel.read(buffer); |
| 822 | if (read==-1) throw new InvalidPlyFormatException("Cannot find the end of the header on the second pass: file has been modified"); |
| 823 | bufferLength+=read; |
| 824 | for (int i=bufferLength-read; i<bufferLength; i++) { |
| 825 | if (buffer.get(i)==(byte)'\n') { |
| 826 | int length=i-lineStart; |
| 827 | if (length==END.length) { |
| 828 | buffer.position(lineStart); |
| 829 | buffer.get(endTest); |
| 830 | buffer.get(); // skip the '\n' |
| 831 | if (Arrays.equals(END, endTest)) { |
| 832 | // done skipping header |
| 833 | buffer.limit(bufferLength); |
| 834 | buffer.compact(); |
| 835 | buffer.flip(); |
| 836 | return; |
| 837 | } |
| 838 | } |
| 839 | lineStart=i+1; |
| 840 | } |
| 841 | } |
| 842 | if (buffer.remaining()==0) { |
| 843 | if (lineStart==0) throw new InvalidPlyFormatException("Line too long"); |
| 844 | buffer.position(lineStart); |
| 845 | buffer.limit(bufferLength); |
| 846 | buffer.compact(); |
| 847 | bufferLength-=lineStart; |
| 848 | lineStart=0; |
| 849 | buffer.limit(buffer.capacity()); |
| 850 | } |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | @Override |
| 855 | public Number read(Type type) throws IOException { |
| 856 | while (true) { |
nothing calls this directly
no outgoing calls
no test coverage detected