This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit cffa1733dc4ecdeb6cfed9b6689d48dce0911b0d Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Mon Jul 17 17:57:16 2023 +0200 In GeoTIFf internal implementation, rename the `readXXX(…)` methods as `readAsXXX(…)` for making clear that those methods perform conversions. --- .../sis/storage/geotiff/ImageFileDirectory.java | 92 +++++++------- .../apache/sis/storage/geotiff/NativeMetadata.java | 10 +- .../java/org/apache/sis/storage/geotiff/Type.java | 138 ++++++++++----------- .../apache/sis/storage/geotiff/XMLMetadata.java | 4 +- .../org/apache/sis/storage/geotiff/TypeTest.java | 8 +- 5 files changed, 126 insertions(+), 126 deletions(-) diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java index 0d255f0953..12bcc7d689 100644 --- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java +++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java @@ -540,7 +540,7 @@ final class ImageFileDirectory extends DataCube { * 2 = Planar format. For example, one plane of Red components, one plane of Green and one plane if Blue. */ case TAG_PLANAR_CONFIGURATION: { - final int value = type.readInt(input(), count); + final int value = type.readAsInt(input(), count); switch (value) { case PLANAR_CONFIGURATION_CHUNKY: isPlanar = false; break; case PLANAR_CONFIGURATION_PLANAR: isPlanar = true; break; @@ -552,14 +552,14 @@ final class ImageFileDirectory extends DataCube { * The number of columns in the image, i.e., the number of pixels per row. */ case TAG_IMAGE_WIDTH: { - imageWidth = type.readUnsignedLong(input(), count); + imageWidth = type.readAsUnsignedLong(input(), count); break; } /* * The number of rows of pixels in the image. */ case TAG_IMAGE_LENGTH: { - imageHeight = type.readUnsignedLong(input(), count); + imageHeight = type.readAsUnsignedLong(input(), count); break; } /* @@ -567,7 +567,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_TILE_WIDTH: { setTileTagFamily(TILE); - tileWidth = type.readInt(input(), count); + tileWidth = type.readAsInt(input(), count); break; } /* @@ -575,7 +575,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_TILE_LENGTH: { setTileTagFamily(TILE); - tileHeight = type.readInt(input(), count); + tileHeight = type.readAsInt(input(), count); break; } /* @@ -584,7 +584,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_ROWS_PER_STRIP: { setTileTagFamily(STRIP); - tileHeight = type.readInt(input(), count); + tileHeight = type.readAsInt(input(), count); break; } /* @@ -592,7 +592,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_TILE_OFFSETS: { setTileTagFamily(TILE); - tileOffsets = type.readVector(input(), count); + tileOffsets = type.readAsVector(input(), count); break; } /* @@ -601,7 +601,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_STRIP_OFFSETS: { setTileTagFamily(STRIP); - tileOffsets = type.readVector(input(), count); + tileOffsets = type.readAsVector(input(), count); break; } /* @@ -609,7 +609,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_TILE_BYTE_COUNTS: { setTileTagFamily(TILE); - tileByteCounts = type.readVector(input(), count); + tileByteCounts = type.readAsVector(input(), count); break; } /* @@ -618,7 +618,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_STRIP_BYTE_COUNTS: { setTileTagFamily(STRIP); - tileByteCounts = type.readVector(input(), count); + tileByteCounts = type.readAsVector(input(), count); break; } /* @@ -626,12 +626,12 @@ final class ImageFileDirectory extends DataCube { */ case TAG_JPEG_INTERCHANGE_FORMAT: { setTileTagFamily(JPEG); - tileOffsets = type.readVector(input(), count); + tileOffsets = type.readAsVector(input(), count); break; } case TAG_JPEG_INTERCHANGE_FORMAT_LENGTH: { setTileTagFamily(JPEG); - tileByteCounts = type.readVector(input(), count); + tileByteCounts = type.readAsVector(input(), count); break; } @@ -646,7 +646,7 @@ final class ImageFileDirectory extends DataCube { * Compression scheme used on the image data. */ case TAG_COMPRESSION: { - final int value = type.readInt(input(), count); + final int value = type.readAsInt(input(), count); compression = Compression.valueOf(value); if (compression == Compression.UNKNOWN) { return value; // Cause a warning to be reported by the caller. @@ -658,7 +658,7 @@ final class ImageFileDirectory extends DataCube { * 1=none, 2=horizontal differencing. More values may be added in the future. */ case TAG_PREDICTOR: { - final int value = type.readInt(input(), count); + final int value = type.readAsInt(input(), count); predictor = Predictor.valueOf(value); if (predictor == Predictor.UNKNOWN) { return value; // Cause a warning to be reported by the caller. @@ -670,7 +670,7 @@ final class ImageFileDirectory extends DataCube { * bits order shall be reversed in every bytes before decompression. */ case TAG_FILL_ORDER: { - final int value = type.readInt(input(), count); + final int value = type.readAsInt(input(), count); switch (value) { case FILL_ORDER_LEFT_TO_RIGHT: isBitOrderReversed = false; break; case FILL_ORDER_RIGHT_TO_LEFT: isBitOrderReversed = true; break; @@ -683,7 +683,7 @@ final class ImageFileDirectory extends DataCube { * specified by the BitsPerSample field. */ case TAG_SAMPLE_FORMAT: { - final int value = type.readInt(input(), count); + final int value = type.readAsInt(input(), count); switch (value) { default: return value; // Warning to be reported by the caller. case SAMPLE_FORMAT_UNSIGNED_INTEGER: sampleFormat = UNSIGNED; break; @@ -702,7 +702,7 @@ final class ImageFileDirectory extends DataCube { * But the TIFF specification allows different values. */ case TAG_BITS_PER_SAMPLE: { - final Vector values = type.readVector(input(), count); + final Vector values = type.readAsVector(input(), count); /* * The current implementation requires that all `bitsPerSample` elements have the same value. * This restriction may be revisited in future Apache SIS versions. @@ -723,7 +723,7 @@ final class ImageFileDirectory extends DataCube { * and 3 for RGB images. Default value is 1. */ case TAG_SAMPLES_PER_PIXEL: { - samplesPerPixel = type.readShort(input(), count); + samplesPerPixel = type.readAsShort(input(), count); break; } /* @@ -733,7 +733,7 @@ final class ImageFileDirectory extends DataCube { * describes the meaning of the extra samples. It may be an alpha channel, but not necessarily. */ case TAG_EXTRA_SAMPLES: { - extraSamples = type.readVector(input(), count); + extraSamples = type.readAsVector(input(), count); break; } @@ -753,7 +753,7 @@ final class ImageFileDirectory extends DataCube { * 4 = Transparency Mask. Defines an irregularly shaped region of another image in the same TIFF file. */ case TAG_PHOTOMETRIC_INTERPRETATION: { - final short value = type.readShort(input(), count); + final short value = type.readAsShort(input(), count); if (value < 0 || value > Byte.MAX_VALUE) return value; photometricInterpretation = (byte) value; break; @@ -766,7 +766,7 @@ final class ImageFileDirectory extends DataCube { * (black is 0,0,0) and 65535 represents the maximum intensity. */ case TAG_COLOR_MAP: { - colorMap = type.readVector(input(), count); + colorMap = type.readAsVector(input(), count); break; } /* @@ -775,7 +775,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_MIN_SAMPLE_VALUE: case TAG_S_MIN_SAMPLE_VALUE: { - minValues = extremum(minValues, type.readVector(input(), count), false); + minValues = extremum(minValues, type.readAsVector(input(), count), false); isMinSpecified = true; break; } @@ -786,7 +786,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_MAX_SAMPLE_VALUE: case TAG_S_MAX_SAMPLE_VALUE: { - maxValues = extremum(maxValues, type.readVector(input(), count), true); + maxValues = extremum(maxValues, type.readAsVector(input(), count), true); isMaxSpecified = true; break; } @@ -807,7 +807,7 @@ final class ImageFileDirectory extends DataCube { * Bit 4 indicates MRC imaging model as described in ITU-T recommendation T.44 [T.44] (See ImageLayer tag) - RFC 2301. */ case TAG_NEW_SUBFILE_TYPE: { - subfileType = type.readInt(input(), count); + subfileType = type.readAsInt(input(), count); break; } /* @@ -817,7 +817,7 @@ final class ImageFileDirectory extends DataCube { * 3 = a single page of a multi-page image (see PageNumber). */ case TAG_SUBFILE_TYPE: { - final int value = type.readInt(input(), count); + final int value = type.readAsInt(input(), count); switch (value) { default: return value; // Warning to be reported by the caller. case SUBFILE_TYPE_FULL_RESOLUTION: subfileType &= ~NEW_SUBFILE_TYPE_REDUCED_RESOLUTION; break; @@ -839,14 +839,14 @@ final class ImageFileDirectory extends DataCube { * The first 4 values are special, and contain GeoKey directory header information. */ case (short) TAG_GEO_KEY_DIRECTORY: { - referencing().keyDirectory = type.readVector(input(), count); + referencing().keyDirectory = type.readAsVector(input(), count); break; } /* * Stores all of the `double` valued GeoKeys, referenced by the GeoKeyDirectory. */ case (short) TAG_GEO_DOUBLE_PARAMS: { - referencing().numericParameters = type.readVector(input(), count); + referencing().numericParameters = type.readAsVector(input(), count); break; } /* @@ -855,7 +855,7 @@ final class ImageFileDirectory extends DataCube { * Note that TIFF files use 0 as the end delimiter in strings (C/C++ convention). */ case (short) TAG_GEO_ASCII_PARAMS: { - referencing().setAsciiParameters(type.readString(input(), count, encoding())); + referencing().setAsciiParameters(type.readAsStrings(input(), count, encoding())); break; } /* @@ -875,7 +875,7 @@ final class ImageFileDirectory extends DataCube { * Only one of `ModelPixelScaleTag` and `ModelTransformationTag` should be used. */ case (short) TAG_MODEL_TRANSFORMATION: { - final Vector m = type.readVector(input(), count); + final Vector m = type.readAsVector(input(), count); final int n; switch (m.size()) { case 6: // Assume 2D model with implicit [0 0 1] last row. @@ -902,7 +902,7 @@ final class ImageFileDirectory extends DataCube { * the tie point. Only one of `ModelPixelScaleTag` and `ModelTransformationTag` should be used. */ case (short) TAG_MODEL_PIXEL_SCALE: { - final Vector m = type.readVector(input(), count); + final Vector m = type.readAsVector(input(), count); final int size = m.size(); if (size < 2 || size > 3) { // Length should be exactly 3, but we make this reader tolerant. return m; @@ -915,7 +915,7 @@ final class ImageFileDirectory extends DataCube { * This tag is also known as `Georeference`. */ case (short) TAG_MODEL_TIE_POINT: { - referencing().modelTiePoints = type.readVector(input(), count); + referencing().modelTiePoints = type.readAsVector(input(), count); break; } @@ -933,7 +933,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/identificationInfo/citation/series/name */ case TAG_DOCUMENT_NAME: { - for (final String value : type.readString(input(), count, encoding())) { + for (final String value : type.readAsStrings(input(), count, encoding())) { metadata.addSeries(value); } break; @@ -944,7 +944,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/identificationInfo/citation/series/page */ case TAG_PAGE_NAME: { - for (final String value : type.readString(input(), count, encoding())) { + for (final String value : type.readAsStrings(input(), count, encoding())) { metadata.addPage(value); } break; @@ -957,7 +957,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/identificationInfo/citation/series/page */ case TAG_PAGE_NUMBER: { - final Vector v = type.readVector(input(), count); + final Vector v = type.readAsVector(input(), count); int p = 0, n = 0; switch (v.size()) { default: n = v.intValue(1); // Fall through @@ -974,7 +974,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/identificationInfo/citation/title */ case TAG_IMAGE_DESCRIPTION: { - for (final String value : type.readString(input(), count, encoding())) { + for (final String value : type.readAsStrings(input(), count, encoding())) { metadata.addTitle(Strings.singleLine(" ", value)); } break; @@ -986,7 +986,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/identificationInfo/citation/party/name */ case TAG_ARTIST: { - for (final String value : type.readString(input(), count, encoding())) { + for (final String value : type.readAsStrings(input(), count, encoding())) { metadata.addAuthor(value); } break; @@ -998,7 +998,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/identificationInfo/resourceConstraint */ case (short) TAG_COPYRIGHT: { - for (final String value : type.readString(input(), count, encoding())) { + for (final String value : type.readAsStrings(input(), count, encoding())) { metadata.parseLegalNotice(value); } break; @@ -1009,7 +1009,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/identificationInfo/citation/date */ case TAG_DATE_TIME: { - for (final String value : type.readString(input(), count, encoding())) { + for (final String value : type.readAsStrings(input(), count, encoding())) { metadata.addCitationDate(reader.getDateFormat().parse(value), DateType.CREATION, MetadataBuilder.Scope.RESOURCE); } @@ -1021,7 +1021,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/resourceLineage/processStep/processingInformation/procedureDescription */ case TAG_HOST_COMPUTER: { - for (final String value : type.readString(input(), count, encoding())) { + for (final String value : type.readAsStrings(input(), count, encoding())) { metadata.addHostComputer(value); } break; @@ -1032,7 +1032,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/resourceLineage/processStep/processingInformation/softwareReference/title */ case TAG_SOFTWARE: { - for (final String value : type.readString(input(), count, encoding())) { + for (final String value : type.readAsStrings(input(), count, encoding())) { metadata.addSoftwareReference(value); } break; @@ -1053,7 +1053,7 @@ final class ImageFileDirectory extends DataCube { * Destination: metadata/acquisitionInformation/platform/instrument/identifier */ case TAG_MODEL: { - for (final String value : type.readString(input(), count, encoding())) { + for (final String value : type.readAsStrings(input(), count, encoding())) { metadata.addInstrument(null, value); } break; @@ -1063,7 +1063,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_X_RESOLUTION: case TAG_Y_RESOLUTION: { - metadata.setResolution(type.readDouble(input(), count)); + metadata.setResolution(type.readAsDouble(input(), count)); break; } /* @@ -1074,7 +1074,7 @@ final class ImageFileDirectory extends DataCube { * 3 = Centimeter. */ case TAG_RESOLUTION_UNIT: { - return metadata.setResolutionUnit(type.readInt(input(), count)); + return metadata.setResolutionUnit(type.readAsInt(input(), count)); // Non-null return value cause a warning to be reported by the caller. } /* @@ -1086,7 +1086,7 @@ final class ImageFileDirectory extends DataCube { * 3 = A randomized process such as error diffusion has been applied to the image data. */ case TAG_THRESHHOLDING: { - return metadata.setThreshholding(type.readShort(input(), count)); + return metadata.setThreshholding(type.readAsShort(input(), count)); // Non-null return value cause a warning to be reported by the caller. } /* @@ -1095,7 +1095,7 @@ final class ImageFileDirectory extends DataCube { */ case TAG_CELL_WIDTH: case TAG_CELL_LENGTH: { - metadata.setCellSize(type.readShort(input(), count), tag == TAG_CELL_WIDTH); + metadata.setCellSize(type.readAsShort(input(), count), tag == TAG_CELL_WIDTH); break; } @@ -1133,7 +1133,7 @@ final class ImageFileDirectory extends DataCube { break; } case Tags.GDAL_NODATA: { - noData = type.readDouble(input(), count); + noData = type.readAsDouble(input(), count); break; } } diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/NativeMetadata.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/NativeMetadata.java index 1d9fb094ba..4a2afc0833 100644 --- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/NativeMetadata.java +++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/NativeMetadata.java @@ -160,17 +160,17 @@ final class NativeMetadata extends GeoKeysLoader { switch (tag) { case (short) TAG_GEO_KEY_DIRECTORY: { writeGeoKeys(); // Flush previous keys if any (should never happen). - keyDirectory = type.readVector(input, count); + keyDirectory = type.readAsVector(input, count); value = "GeoTIFF"; break; } case (short) TAG_GEO_DOUBLE_PARAMS: { - numericParameters = type.readVector(input, count); + numericParameters = type.readAsVector(input, count); visible = false; break; } case (short) TAG_GEO_ASCII_PARAMS: { - setAsciiParameters(type.readString(input, count, reader.store.encoding)); + setAsciiParameters(type.readAsStrings(input, count, reader.store.encoding)); visible = false; break; } @@ -179,12 +179,12 @@ final class NativeMetadata extends GeoKeysLoader { children = new XMLMetadata(reader, type, count, tag); if (children.isEmpty()) { // Fallback on showing array of numerical values. - value = type.readVector(input, count); + value = type.readAsVector(input, count); } break; } default: { - value = type.readObject(input, count); + value = type.readAsObject(input, count); if (value instanceof Vector) { final Vector v = (Vector) value; switch (v.size()) { diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java index c1585e4c69..17819c544b 100644 --- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java +++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java @@ -49,12 +49,12 @@ enum Type { * </ul> */ UNDEFINED(7, Byte.BYTES, false) { - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { throw new UnsupportedOperationException(name()); } /** Unknown value (used for reporting native metadata only). */ - @Override public Object readObject(final ChannelDataInput input, final long count) throws IOException { + @Override public Object readAsObject(final ChannelDataInput input, final long count) throws IOException { return null; } }, @@ -67,7 +67,7 @@ enum Type { * </ul> */ BYTE(6, Byte.BYTES, false) { - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { final long value = input.readByte(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readByte(), count); @@ -75,7 +75,7 @@ enum Type { return value; } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readBytes(count); } }, @@ -88,7 +88,7 @@ enum Type { * </ul> */ UBYTE(1, Byte.BYTES, true) { - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { final long value = input.readUnsignedByte(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readUnsignedByte(), count); @@ -96,7 +96,7 @@ enum Type { return value; } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readBytes(count); } }, @@ -109,7 +109,7 @@ enum Type { * </ul> */ SHORT(8, Short.BYTES, false) { - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { final long value = input.readShort(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readShort(), count); @@ -117,7 +117,7 @@ enum Type { return value; } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readShorts(count); } }, @@ -130,7 +130,7 @@ enum Type { * </ul> */ USHORT(3, Short.BYTES, true) { - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { final long value = input.readUnsignedShort(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readUnsignedShort(), count); @@ -138,7 +138,7 @@ enum Type { return value; } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readShorts(count); } }, @@ -151,7 +151,7 @@ enum Type { * </ul> */ INT(9, Integer.BYTES, false) { - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { final long value = input.readInt(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readInt(), count); @@ -159,7 +159,7 @@ enum Type { return value; } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readInts(count); } }, @@ -172,7 +172,7 @@ enum Type { * </ul> */ UINT(4, Integer.BYTES, true) { - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { final long value = input.readUnsignedInt(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readUnsignedInt(), count); @@ -180,7 +180,7 @@ enum Type { return value; } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readInts(count); } }, @@ -192,7 +192,7 @@ enum Type { * </ul> */ LONG(17, Long.BYTES, false) { - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { final long value = input.readLong(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readLong(), count); @@ -200,7 +200,7 @@ enum Type { return value; } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readLongs(count); } }, @@ -212,7 +212,7 @@ enum Type { * </ul> */ ULONG(16, Long.BYTES, true) { - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { final long value = input.readLong(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readLong(), count); @@ -223,11 +223,11 @@ enum Type { throw new ArithmeticException(canNotConvert(Long.toUnsignedString(value))); } - @Override public double readDouble(final ChannelDataInput input, final long count) throws IOException { - return Numerics.toUnsignedDouble(readLong(input, count)); + @Override public double readAsDouble(final ChannelDataInput input, final long count) throws IOException { + return Numerics.toUnsignedDouble(readAsLong(input, count)); } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readLongs(count); } }, @@ -240,7 +240,7 @@ enum Type { * </ul> */ FLOAT(11, Float.BYTES, false) { - private float readFloat(final ChannelDataInput input, final long count) throws IOException { + private float readAsFloat(final ChannelDataInput input, final long count) throws IOException { final float value = input.readFloat(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readFloat(), count); @@ -248,8 +248,8 @@ enum Type { return value; } - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { - final float value = readFloat(input, count); + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { + final float value = readAsFloat(input, count); final long r = (long) value; if (r == value) { return r; @@ -257,11 +257,11 @@ enum Type { throw new ArithmeticException(canNotConvert(Float.toString(value))); } - @Override public double readDouble(final ChannelDataInput input, final long count) throws IOException { - return DecimalFunctions.floatToDouble(readFloat(input, count)); + @Override public double readAsDouble(final ChannelDataInput input, final long count) throws IOException { + return DecimalFunctions.floatToDouble(readAsFloat(input, count)); } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readFloats(count); } }, @@ -274,7 +274,7 @@ enum Type { * </ul> */ DOUBLE(12, Double.BYTES, false) { - @Override public double readDouble(final ChannelDataInput input, final long count) throws IOException { + @Override public double readAsDouble(final ChannelDataInput input, final long count) throws IOException { final double value = input.readDouble(); for (long i=1; i<count; i++) { ensureSingleton(value, input.readDouble(), count); @@ -282,7 +282,7 @@ enum Type { return value; } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return input.readDoubles(count); } }, @@ -295,16 +295,16 @@ enum Type { * </ul> */ RATIONAL(10, (2*Integer.BYTES), false) { - @Override public double readDouble(final ChannelDataInput input, final long count) throws IOException { + @Override public double readAsDouble(final ChannelDataInput input, final long count) throws IOException { return readFraction(input, count).doubleValue(); } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return readFractions(input, count); } - @Override public Object readObject(final ChannelDataInput input, final long count) throws IOException { - return (count == 1) ? readFraction(input, count) : super.readObject(input, count); + @Override public Object readAsObject(final ChannelDataInput input, final long count) throws IOException { + return (count == 1) ? readFraction(input, count) : super.readAsObject(input, count); } }, @@ -316,16 +316,16 @@ enum Type { * </ul> */ URATIONAL(5, (2*Integer.BYTES), true) { - @Override public double readDouble(final ChannelDataInput input, final long count) throws IOException { + @Override public double readAsDouble(final ChannelDataInput input, final long count) throws IOException { return readFraction(input, count).doubleValue(); } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { return readFractions(input, count); } - @Override public Object readObject(final ChannelDataInput input, final long count) throws IOException { - return (count == 1) ? readFraction(input, count) : super.readObject(input, count); + @Override public Object readAsObject(final ChannelDataInput input, final long count) throws IOException { + return (count == 1) ? readFraction(input, count) : super.readAsObject(input, count); } }, @@ -339,7 +339,7 @@ enum Type { * </ul> */ ASCII(2, Byte.BYTES, false) { - @Override public String[] readString(final ChannelDataInput input, final long length, final Charset charset) throws IOException { + @Override public String[] readAsStrings(final ChannelDataInput input, final long length, final Charset charset) throws IOException { final byte[] chars = input.readBytes(Math.toIntExact(length)); String[] lines = new String[1]; // We will usually have exactly one string. int count = 0, lower = 0; @@ -355,8 +355,8 @@ enum Type { } /** Returns the singleton string, or {@code null} if none. */ - private String readString(final ChannelDataInput input, final long count, final boolean mandatory) throws IOException { - final String[] lines = readString(input, count, StandardCharsets.US_ASCII); + private String readAsString(final ChannelDataInput input, final long count, final boolean mandatory) throws IOException { + final String[] lines = readAsStrings(input, count, StandardCharsets.US_ASCII); if (lines.length != 0) { final String value = lines[0]; int i = 1; @@ -368,24 +368,24 @@ enum Type { throw new IllegalArgumentException(Errors.format(Errors.Keys.UnexpectedArrayLength_2, 1, lines.length)); } - @Override public long readLong(final ChannelDataInput input, final long count) throws IOException { - return Long.parseLong(readString(input, count, true)); + @Override public long readAsLong(final ChannelDataInput input, final long count) throws IOException { + return Long.parseLong(readAsString(input, count, true)); } - @Override public double readDouble(final ChannelDataInput input, final long count) throws IOException { - String text = readString(input, count, false); + @Override public double readAsDouble(final ChannelDataInput input, final long count) throws IOException { + String text = readAsString(input, count, false); if (text == null || (text = text.trim()).isEmpty() || text.equalsIgnoreCase("NaN")) { return Double.NaN; } return Double.parseDouble(text); } - @Override public Object readArray(final ChannelDataInput input, final int count) throws IOException { - return readString(input, count, StandardCharsets.US_ASCII); + @Override public Object readAsArray(final ChannelDataInput input, final int count) throws IOException { + return readAsStrings(input, count, StandardCharsets.US_ASCII); } - @Override public Object readObject(final ChannelDataInput input, final long count) throws IOException { - return readString(input, count, false); + @Override public Object readAsObject(final ChannelDataInput input, final long count) throws IOException { + return readAsString(input, count, false); } }; @@ -472,7 +472,7 @@ enum Type { /** * Invoked by {@code read(…)} method implementations for verifying that the {@code count} argument value is 1. - * All read methods other than {@code readArray(…)} expect exactly one value, except methods in {@link #ASCII} + * All read methods other than {@code readAsArray(…)} expect exactly one value, except methods in {@link #ASCII} * enumeration value which are treated differently. * * <p>While exactly one value is expected, we are tolerant to longer arrays provided that all values are the @@ -519,8 +519,8 @@ enum Type { * @throws IllegalArgumentException if the value is not a singleton. * @throws UnsupportedOperationException if this type is {@link #UNDEFINED}. */ - public final short readShort(final ChannelDataInput input, final long count) throws IOException { - final long value = readLong(input, count); + public final short readAsShort(final ChannelDataInput input, final long count) throws IOException { + final long value = readAsLong(input, count); if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { return (short) value; } @@ -540,8 +540,8 @@ enum Type { * @throws IllegalArgumentException if the value is not a singleton. * @throws UnsupportedOperationException if this type is {@link #UNDEFINED}. */ - public final int readInt(final ChannelDataInput input, final long count) throws IOException { - final long value = readLong(input, count); + public final int readAsInt(final ChannelDataInput input, final long count) throws IOException { + final long value = readAsLong(input, count); if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) { return (int) value; } @@ -558,8 +558,8 @@ enum Type { * @throws IllegalArgumentException if the value is not a singleton. * @throws UnsupportedOperationException if this type is {@link #UNDEFINED}. */ - public final long readUnsignedLong(final ChannelDataInput input, final long count) throws IOException { - final long value = readLong(input, count); + public final long readAsUnsignedLong(final ChannelDataInput input, final long count) throws IOException { + final long value = readAsLong(input, count); if (value >= 0) { return value; } @@ -583,9 +583,9 @@ enum Type { * @throws IllegalArgumentException if the value is not a singleton. * @throws UnsupportedOperationException if this type is {@link #UNDEFINED}. */ - public long readLong(final ChannelDataInput input, final long count) throws IOException { - // All enum MUST override one of 'readLong' or 'readDouble' methods. - final double value = readDouble(input, count); + public long readAsLong(final ChannelDataInput input, final long count) throws IOException { + // All enum MUST override one of `readAsLong(…)` or `readAsDouble(…)` methods. + final double value = readAsDouble(input, count); final long r = (long) value; if (r == value) { return r; @@ -609,9 +609,9 @@ enum Type { * @throws IllegalArgumentException if the value is not a singleton. * @throws UnsupportedOperationException if this type is {@link #UNDEFINED}. */ - public double readDouble(ChannelDataInput input, long count) throws IOException { - // All enum MUST override one of 'readLong' or 'readDouble' methods. - return readLong(input, count); + public double readAsDouble(ChannelDataInput input, long count) throws IOException { + // All enum MUST override one of `readAsLong(…)` or `readAsDouble(…)` methods. + return readAsLong(input, count); } /** @@ -625,10 +625,10 @@ enum Type { * @throws ArithmeticException if the given length is too large. * @throws UnsupportedOperationException if this type is {@link #UNDEFINED}. */ - public String[] readString(final ChannelDataInput input, final long length, final Charset charset) throws IOException { + public String[] readAsStrings(final ChannelDataInput input, final long length, final Charset charset) throws IOException { final String[] s = new String[Math.toIntExact(length)]; for (int i=0; i<s.length; i++) { - final double value = readDouble(input, 1); + final double value = readAsDouble(input, 1); final long r = (long) value; s[i] = (r == value) ? String.valueOf(r) : String.valueOf(value); } @@ -638,15 +638,15 @@ enum Type { /** * Returns the value as a {@link Vector}, a {@link Number} (only for fractions) or a {@link String} instance. * This method should be overridden by all enumeration values that do no override - * {@link #readArray(ChannelDataInput, int)}. + * {@link #readAsArray(ChannelDataInput, int)}. * * @param input the input from where to read the values. * @param count the amount of values. * @return the value as a Java array or a {@link String}, or {@code null} if undefined. * @throws IOException if an error occurred while reading the stream. */ - public Object readObject(ChannelDataInput input, long count) throws IOException { - return readVector(input, count); + public Object readAsObject(ChannelDataInput input, long count) throws IOException { + return readAsVector(input, count); } /** @@ -660,14 +660,14 @@ enum Type { * @throws IOException if an error occurred while reading the stream. * @throws UnsupportedOperationException if this type is {@link #UNDEFINED}. */ - public Object readArray(ChannelDataInput input, int count) throws IOException { + public Object readAsArray(ChannelDataInput input, int count) throws IOException { throw new UnsupportedOperationException(name()); } /** * Reads an arbitrary number of values as a wrapper around a Java array of primitive type. * This wrapper provide a more convenient way to access array elements than the object - * returned by {@link #readArray(ChannelDataInput, int)}. + * returned by {@link #readAsArray(ChannelDataInput, int)}. * * @param input the input from where to read the values. * @param count the amount of values. @@ -677,7 +677,7 @@ enum Type { * @throws NumberFormatException if the value was stored in ASCII and cannot be parsed. * @throws UnsupportedOperationException if this type is {@link #UNDEFINED}. */ - public final Vector readVector(final ChannelDataInput input, final long count) throws IOException { - return Vector.create(readArray(input, Math.toIntExact(count)), isUnsigned); + public final Vector readAsVector(final ChannelDataInput input, final long count) throws IOException { + return Vector.create(readAsArray(input, Math.toIntExact(count)), isUnsigned); } } diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/XMLMetadata.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/XMLMetadata.java index 75408c3d6e..438cda34c0 100644 --- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/XMLMetadata.java +++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/XMLMetadata.java @@ -139,7 +139,7 @@ final class XMLMetadata implements Filter { listeners = reader.store.listeners(); switch (type) { case ASCII: { - final String[] cs = type.readString(reader.input, count, reader.store.encoding); + final String[] cs = type.readAsStrings(reader.input, count, reader.store.encoding); switch (cs.length) { case 0: break; case 1: string = cs[0]; break; // Usual case. @@ -153,7 +153,7 @@ final class XMLMetadata implements Filter { * NoSuchElementException, ClassCastException and UnsupportedOperationException * should never happen here because we verified that the vector type is byte. */ - bytes = ((ByteBuffer) type.readVector(reader.input, count).buffer().get()).array(); + bytes = ((ByteBuffer) type.readAsVector(reader.input, count).buffer().get()).array(); break; } } diff --git a/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/TypeTest.java b/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/TypeTest.java index 4f193968f7..5a1cf4935f 100644 --- a/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/TypeTest.java +++ b/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/TypeTest.java @@ -38,8 +38,8 @@ public final class TypeTest extends TestCase { } /** - * Verifies that all enumeration values override either {@link Type#readLong(ChannelDataInput, long)} - * or {@link Type#readDouble(ChannelDataInput, long)}.Failing to do so may cause stack overflow. + * Verifies that all enumeration values override either {@link Type#readAsLong(ChannelDataInput, long)} + * or {@link Type#readAsDouble(ChannelDataInput, long)}. Failing to do so may cause stack overflow. * * @throws NoSuchMethodException if a reflective operation failed. */ @@ -51,8 +51,8 @@ public final class TypeTest extends TestCase { }; for (final Type type : Type.values()) { final Class<?> c = type.getClass(); - final boolean readLong = c.getMethod("readLong", parameters).getDeclaringClass() == Type.class; - final boolean readDouble = c.getMethod("readDouble", parameters).getDeclaringClass() == Type.class; + final boolean readLong = c.getMethod("readAsLong", parameters).getDeclaringClass() == Type.class; + final boolean readDouble = c.getMethod("readAsDouble", parameters).getDeclaringClass() == Type.class; assertFalse(type.name(), readLong & readDouble); } }