Changeset 36160 in osm for applications/editors/josm/plugins
- Timestamp:
- 2023-10-05T15:52:30+02:00 (14 months ago)
- Location:
- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitReader.java
r36151 r36160 27 27 import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitRecordNormalHeader; 28 28 import org.openstreetmap.josm.plugins.fit.lib.records.internal.IField; 29 import org.openstreetmap.josm.plugins.fit.lib.utils.CountingInputStream; 29 30 import org.openstreetmap.josm.plugins.fit.lib.utils.NumberUtils; 30 31 … … 48 49 */ 49 50 public static FitData[] read(InputStream inputStream, FitReaderOptions... options) throws FitException { 50 final var bufferedInputStream = inputStream.markSupported() ? inputStream51 : new BufferedInputStream(inputStream);51 final var bufferedInputStream = new CountingInputStream( 52 inputStream.markSupported() ? inputStream : new BufferedInputStream(inputStream)); 52 53 final var optionsSet = options.length == 0 ? EnumSet.noneOf(FitReaderOptions.class) 53 54 : EnumSet.of(options[0], options); … … 55 56 try { 56 57 final var header = readFitHeader(bufferedInputStream); 58 final var headerSize = bufferedInputStream.bytesRead(); 57 59 bufferedInputStream.mark(1); 58 60 var localMessageHeaders = new FitDefinitionMessage[1]; … … 61 63 var offsetAddition = 0; 62 64 byte lastOffset = 0; 63 while (bufferedInputStream.read() != -1) { 65 while (bufferedInputStream.read() != -1 66 && bufferedInputStream.bytesRead() < header.dataSize() - headerSize) { 64 67 bufferedInputStream.reset(); 65 68 final var nextRecordHeader = readNextRecordHeader(bufferedInputStream); … … 125 128 } catch (FitException fitException) { 126 129 handleException(optionsSet, fitException); 127 } catch (I OException ioException) {130 } catch (IllegalArgumentException | IOException ioException) { 128 131 handleException(optionsSet, new FitException(ioException)); 129 132 } … … 199 202 final var globalMessageNumber = NumberUtils.decodeInt(2, littleEndian, inputStream); 200 203 final int numberOfFields = inputStream.read(); 201 final var fitFields = new ArrayList<FitField>( numberOfFields);204 final var fitFields = new ArrayList<FitField>(Math.max(0, numberOfFields)); 202 205 for (var i = 0; i < numberOfFields; i++) { 203 206 fitFields.add(readNextField(inputStream));
Note:
See TracChangeset
for help on using the changeset viewer.