Changeset 13061 in josm for trunk/src/com/drew/lang/StreamReader.java
- Timestamp:
- 2017-10-30T22:46:09+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/lang/StreamReader.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 37 37 private final InputStream _stream; 38 38 39 private long _pos; 40 41 @Override 42 public long getPosition() 43 { 44 return _pos; 45 } 46 47 @SuppressWarnings("ConstantConditions") 39 48 public StreamReader(@NotNull InputStream stream) 40 49 { … … 43 52 44 53 _stream = stream; 54 _pos = 0; 45 55 } 46 56 47 57 @Override 48 p rotectedbyte getByte() throws IOException58 public byte getByte() throws IOException 49 59 { 50 60 int value = _stream.read(); 51 61 if (value == -1) 52 62 throw new EOFException("End of data reached."); 63 _pos++; 53 64 return (byte)value; 54 65 } … … 59 70 { 60 71 byte[] bytes = new byte[count]; 72 getBytes(bytes, 0, count); 73 return bytes; 74 } 75 76 @Override 77 public void getBytes(@NotNull byte[] buffer, int offset, int count) throws IOException 78 { 61 79 int totalBytesRead = 0; 62 63 while (totalBytesRead != count){64 final int bytesRead = _stream.read(b ytes,totalBytesRead, count - totalBytesRead);80 while (totalBytesRead != count) 81 { 82 final int bytesRead = _stream.read(buffer, offset + totalBytesRead, count - totalBytesRead); 65 83 if (bytesRead == -1) 66 84 throw new EOFException("End of data reached."); … … 68 86 assert(totalBytesRead <= count); 69 87 } 70 71 return bytes; 88 _pos += totalBytesRead; 72 89 } 73 90 … … 93 110 } 94 111 112 @Override 113 public int available() { 114 try { 115 return _stream.available(); 116 } catch (IOException e) { 117 return 0; 118 } 119 } 120 95 121 private long skipInternal(long n) throws IOException 96 122 { … … 109 135 break; 110 136 } 137 _pos += skippedTotal; 111 138 return skippedTotal; 112 139 }
Note:
See TracChangeset
for help on using the changeset viewer.