From c86afa3f07c4912b85e909d4498a450e06a1f53d Mon Sep 17 00:00:00 2001 From: Vladislav Fuks Date: Tue, 14 Jan 2020 15:21:29 +0100 Subject: [PATCH 1/7] MOD RandomAccessFile: added methods for reading strings with defined charset. MOD H5iosp, H5headerNew, H4iosp, H4header, N3iosp, N3header: added logic for defining charset for reading netcdf files. This definition is made by sending charset as a message to the IOSP object. If charset was not set the default UTF-8 charset will be used as before. The definition of charset is needed because there are tools that create netcdf-files without considering of usage of UTF-8 charset and just use the local charset to write text. Added logic for simple creation of new iosp/header for different netcdf-3 file format: Uniplot CDH format that is netcdf3 with "CDH" magic, little endian byte order and ISO 88591-1 encoding. --- .../ucar/nc2/internal/iosp/hdf4/H4header.java | 48 +++++++++++----- .../ucar/nc2/internal/iosp/hdf4/H4iosp.java | 51 ++++++++++++++--- .../nc2/internal/iosp/hdf5/H5headerNew.java | 23 ++++++-- .../nc2/internal/iosp/hdf5/H5iospNew.java | 30 ++++++++++ .../internal/iosp/netcdf3/N3headerNew.java | 56 +++++++++++++++++-- .../nc2/internal/iosp/netcdf3/N3iospNew.java | 38 ++++++++++++- .../ucar/unidata/io/RandomAccessFile.java | 29 +++++++++- 7 files changed, 241 insertions(+), 34 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java index 128ab18be2..04e63e1b38 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java @@ -10,6 +10,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; @@ -104,7 +105,28 @@ public static void useHdfEos(boolean val) { private Map refnoMap = new HashMap<>(); private MemTracker memTracker; - private PrintWriter debugOut = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)); + private PrintWriter debugOut; + + private final Charset valueCharset; + + public H4header() { + valueCharset = StandardCharsets.UTF_8; + debugOut = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)); + } + + H4header(H4iosp h4iosp) { + valueCharset = h4iosp.getValueCharset().orElse(StandardCharsets.UTF_8); + debugOut = new PrintWriter(new OutputStreamWriter(System.out, valueCharset)); + } + + /** + * Return defined {@link Charset value charset} that + * will be used by reading netcdf file. + * @return {@link Charset value charset} + */ + protected Charset getValueCharset() { + return valueCharset; + } public boolean isEos() { return isEos; @@ -429,11 +451,11 @@ private Attribute makeAttribute(TagVH vh) throws IOException { case 3: case 4: if (nelems == 1) - att = new Attribute(name, raf.readStringMax(size)); + att = new Attribute(name, raf.readStringMax(size, valueCharset)); else { String[] vals = new String[nelems]; for (int i = 0; i < nelems; i++) - vals[i] = raf.readStringMax(size); + vals[i] = raf.readStringMax(size, valueCharset); att = new Attribute(name, Array.factory(DataType.STRING, new int[] {nelems}, vals)); } break; @@ -1139,7 +1161,7 @@ List readChunks(NetcdfFile ncfile) throws IOException { String read() throws IOException { raf.seek(data.offset); - return raf.readString(data.length); + return raf.readString(data.length, valueCharset); } public String toString() { @@ -1639,7 +1661,7 @@ protected void read() throws IOException { major = raf.readInt(); minor = raf.readInt(); release = raf.readInt(); - name = raf.readStringMax(length - 12); + name = raf.readStringMax(length - 12, valueCharset); } public String value() { @@ -1661,7 +1683,7 @@ private class TagText extends Tag { protected void read() throws IOException { raf.seek(offset); - text = raf.readStringMax(length); + text = raf.readStringMax(length, valueCharset); } public String detail() { @@ -1683,7 +1705,7 @@ protected void read() throws IOException { raf.seek(offset); obj_tagno = raf.readShort(); obj_refno = raf.readShort(); - text = raf.readStringMax(length - 4).trim(); + text = raf.readStringMax(length - 4, valueCharset).trim(); } public String detail() { @@ -1840,7 +1862,7 @@ protected void read(int n) throws IOException { int start = 0; for (int i = 0; i < length; i++) { if (b[i] == 0) { - text[count] = new String(b, start, i - start, StandardCharsets.UTF_8); + text[count] = new String(b, start, i - start, valueCharset); count++; if (count == n) break; @@ -1956,9 +1978,9 @@ protected void read() throws IOException { elem_ref[i] = raf.readShort(); short len = raf.readShort(); - name = raf.readStringMax(len); + name = raf.readStringMax(len, valueCharset); len = raf.readShort(); - className = raf.readStringMax(len); + className = raf.readStringMax(len, valueCharset); extag = raf.readShort(); exref = raf.readShort(); @@ -2032,14 +2054,14 @@ protected void read() throws IOException { fld_name = new String[nfields]; for (int i = 0; i < nfields; i++) { short len = raf.readShort(); - fld_name[i] = raf.readStringMax(len); + fld_name[i] = raf.readStringMax(len, valueCharset); } short len = raf.readShort(); - name = raf.readStringMax(len); + name = raf.readStringMax(len, valueCharset); len = raf.readShort(); - className = raf.readStringMax(len); + className = raf.readStringMax(len, valueCharset); extag = raf.readShort(); exref = raf.readShort(); diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java index 70311fd362..c649c73c81 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java @@ -9,7 +9,10 @@ import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.util.List; +import java.util.Optional; + import ucar.ma2.Array; import ucar.ma2.ArrayStructure; import ucar.ma2.ArrayStructureBB; @@ -41,7 +44,8 @@ public class H4iosp extends AbstractIOServiceProvider { private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(H4iosp.class); private static boolean showLayoutTypes; - private H4header header = new H4header(); + private H4header header; + private Charset valueCharset; @Override public boolean isValidFile(RandomAccessFile raf) throws IOException { @@ -50,8 +54,9 @@ public boolean isValidFile(RandomAccessFile raf) throws IOException { @Override public String getFileTypeId() { - if (header.isEos()) + if (header != null && header.isEos()) { return "HDF4-EOS"; + } return DataFormatType.HDF4.getDescription(); } @@ -64,11 +69,23 @@ public String getFileTypeDescription() { public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException { super.open(raf, ncfile, cancelTask); Group.Builder rootGroup = Group.builder(null).setName("").setNcfile(ncfile); - header.read(raf, rootGroup, null); + getHeader().read(raf, rootGroup, null); ncfile.setRootGroup(rootGroup.build(null)); ncfile.finish(); } + /** + * Return header for reading netcdf file. + * Create it if it's not already created. + * @return header for reading netcdf file. + */ + private H4header getHeader() { + if (header == null) { + header = new H4header(this); + } + return header; + } + @Override public boolean isBuilder() { return true; @@ -79,7 +96,7 @@ public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask canc super.open(raf, rootGroup.getNcfile(), cancelTask); raf.order(RandomAccessFile.BIG_ENDIAN); - header = new H4header(); + header = new H4header(this); header.read(raf, rootGroup, null); } @@ -475,14 +492,34 @@ public ByteBuffer getByteBuffer() throws IOException { @Override public void reacquire() throws IOException { super.reacquire(); - header.raf = this.raf; + getHeader().raf = this.raf; } public Object sendIospMessage(Object message) { - if (message.toString().equals("header")) - return header; + if (message instanceof Charset) { + setValueCharset((Charset) message); + } + if (message.toString().equals("header")) { + return getHeader(); + } return super.sendIospMessage(message); } + /** + * Return {@link Charset value charset} if it was defined. Definition of charset + * occurs by sending a charset as a message using the {@link #sendIospMessage} + * method. + * @return {@link Charset value charset} if it was defined. + */ + protected Optional getValueCharset() { + return Optional.ofNullable(valueCharset); + } + /** + * Define {@link Charset value charset}. + * @param charset may be null. + */ + protected void setValueCharset(Charset charset) { + valueCharset = charset; + } } diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java index 899aee7a91..3378097b8a 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java @@ -15,6 +15,7 @@ import java.nio.IntBuffer; import java.nio.LongBuffer; import java.nio.ShortBuffer; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Formatter; @@ -177,10 +178,22 @@ public static boolean isValidFile(RandomAccessFile raf) throws IOException { private PrintWriter debugOut; private MemTracker memTracker; + private final Charset valueCharset; + H5headerNew(RandomAccessFile myRaf, Group.Builder root, H5iospNew h5iosp) { this.raf = myRaf; this.root = root; this.h5iosp = h5iosp; + valueCharset = h5iosp.getValueCharset().orElse(StandardCharsets.UTF_8); + } + + /** + * Return defined {@link Charset value charset} that + * will be used by reading netcdf file. + * @return {@link Charset value charset} + */ + protected Charset getValueCharset() { + return valueCharset; } public void read(PrintWriter debugPS) throws IOException { @@ -189,7 +202,7 @@ public void read(PrintWriter debugPS) throws IOException { } else if (debug1 || debugContinueMessage || debugCreationOrder || debugDetail || debugDimensionScales || debugGroupBtree || debugHardLink || debugHeap || debugPos || debugReference || debugTracker || debugV || debugSoftLink || warnings) { - debugOut = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)); + debugOut = new PrintWriter(new OutputStreamWriter(System.out, valueCharset)); } h5objects = new H5objects(this, debugOut, memTracker); @@ -1194,7 +1207,7 @@ private String convertString(byte[] b) { break; count++; } - return new String(b, 0, count, StandardCharsets.UTF_8); // all strings are considered to be UTF-8 unicode + return new String(b, 0, count, valueCharset); // all strings are considered to be UTF-8 unicode } private String convertString(byte[] b, int start, int len) { @@ -1205,7 +1218,7 @@ private String convertString(byte[] b, int start, int len) { break; count++; } - return new String(b, start, count - start, StandardCharsets.UTF_8); // all strings are considered to be UTF-8 + return new String(b, start, count - start, valueCharset); // all strings are considered to be UTF-8 // unicode } @@ -2103,7 +2116,7 @@ String readHeapString(long heapIdAddress) throws IOException { if (ho.dataSize > 1000 * 1000) return String.format("Bad HeapObject.dataSize=%s", ho); raf.seek(ho.dataPos); - return raf.readString((int) ho.dataSize); + return raf.readString((int) ho.dataSize, valueCharset); } /** @@ -2120,7 +2133,7 @@ String readHeapString(ByteBuffer bb, int pos) throws IOException { if (ho == null) throw new IllegalStateException("Cant find Heap Object,heapId=" + heapId); raf.seek(ho.dataPos); - return raf.readString((int) ho.dataSize); + return raf.readString((int) ho.dataSize, valueCharset); } Array readHeapVlen(ByteBuffer bb, int pos, DataType dataType, int endian) throws IOException, InvalidRangeException { diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java index 46603b3433..41c9868f14 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java @@ -7,6 +7,9 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.charset.Charset; +import java.util.Optional; + import ucar.ma2.Array; import ucar.ma2.ArrayStructure; import ucar.ma2.ArrayStructureBB; @@ -105,6 +108,7 @@ public boolean isBuilder() { private H5headerNew header; private boolean isEos; boolean includeOriginalAttributes; + private Charset valueCharset; @Override public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException { @@ -126,6 +130,32 @@ public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask canc } } + @Override + public Object sendIospMessage(Object message) { + if (message instanceof Charset) { + setValueCharset((Charset) message); + } + return super.sendIospMessage(message); + } + + /** + * Return {@link Charset value charset} if it was defined. Definition of charset + * occurs by sending a charset as a message using the {@link #sendIospMessage} + * method. + * @return {@link Charset value charset} if it was defined. + */ + protected Optional getValueCharset() { + return Optional.ofNullable(valueCharset); + } + + /** + * Define {@link Charset value charset}. + * @param charset may be null. + */ + protected void setValueCharset(Charset charset) { + valueCharset = charset; + } + @Override public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException { super.open(raf, ncfile, cancelTask); diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java index 59809c2ff2..7570cc2920 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java @@ -4,6 +4,7 @@ */ package ucar.nc2.internal.iosp.netcdf3; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import ucar.ma2.*; import ucar.nc2.*; @@ -70,6 +71,8 @@ static class Vinfo { private long dataStart = Long.MAX_VALUE; // where the data starts + private final Charset valueCharset; + /* * Notes: * In netcdf-3 are dimensions signed or unsigned? @@ -78,6 +81,23 @@ static class Vinfo { * little less than 4 GiB, which is twice the size limit in versions earlier than netCDF 3.6." */ + public N3headerNew() { + valueCharset = StandardCharsets.UTF_8; + } + + protected N3headerNew(N3iospNew n3iospNew) { + valueCharset = n3iospNew.getValueCharset().orElse(StandardCharsets.UTF_8); + } + + /** + * Return defined {@link Charset value charset} that + * will be used by reading netcdf file. + * @return {@link Charset value charset} + */ + protected Charset getValueCharset() { + return valueCharset; + } + /** * Read the header and populate the ncfile * @@ -96,14 +116,14 @@ void read(RandomAccessFile raf, Group.Builder root, Formatter debugOut) throws I // netcdf magic number long pos = 0; - raf.order(RandomAccessFile.BIG_ENDIAN); + raf.order(getByteOrder()); raf.seek(pos); byte[] b = new byte[4]; raf.readFully(b); - for (int i = 0; i < 3; i++) - if (b[i] != MAGIC[i]) - throw new IOException("Not a netCDF file " + raf.getLocation()); + if (!isMagicBytes(b)) { + throw new IOException("Not a netCDF file " + raf.getLocation()); + } if ((b[3] != 1) && (b[3] != 2)) throw new IOException("Not a netCDF file " + raf.getLocation()); useLongOffset = (b[3] == 2); @@ -319,6 +339,32 @@ void read(RandomAccessFile raf, Group.Builder root, Formatter debugOut) throws I } } + /** + * Return the byte order that will be used by + * {@link #read(RandomAccessFile, Group.Builder, Formatter) reading file}. + * @return file byte order ({@link RandomAccessFile#BIG_ENDIAN big endian} or + * {@link RandomAccessFile#LITTLE_ENDIAN little endian}) + */ + protected int getByteOrder() { + return RandomAccessFile.BIG_ENDIAN; + } + + /** + * Check if the given bytes correspond to + * {@link #MAGIC magic bytes} of the header. + * @param bytes given bytes. + * @return true if the given bytes correspond to + * {@link #MAGIC magic bytes} of the header. Otherwise false. + */ + protected boolean isMagicBytes(byte[] bytes) { + for (int i = 0; i < 3; i++) { + if (bytes[i] != MAGIC[i]) { + return false; + } + } + return true; + } + long calcFileSize() { if (udim != null) return recStart + recsize * numrecs; @@ -519,7 +565,7 @@ private String readString() throws IOException { count++; } - return new String(b, 0, count, StandardCharsets.UTF_8); // all strings are considered to be UTF-8 unicode. + return new String(b, 0, count, valueCharset); // all strings are considered to be UTF-8 unicode. } // skip to a 4 byte boundary in the file diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java index 8b912b93ca..744a1af274 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java @@ -4,7 +4,10 @@ import java.io.File; import java.io.IOException; import java.nio.channels.WritableByteChannel; +import java.nio.charset.Charset; import java.util.Formatter; +import java.util.Optional; + import ucar.ma2.Array; import ucar.ma2.ArrayStructureBB; import ucar.ma2.DataType; @@ -77,6 +80,8 @@ public class N3iospNew extends AbstractIOServiceProvider implements IOServicePro protected long lastModified; // used by sync protected boolean debug, debugRecord, debugRead; + private Charset valueCharset; + @Override public boolean isValidFile(ucar.unidata.io.RandomAccessFile raf) throws IOException { return N3headerNew.isValidFile(raf); @@ -116,7 +121,7 @@ public void open(ucar.unidata.io.RandomAccessFile raf, ucar.nc2.NetcdfFile ncfil } raf.order(RandomAccessFile.BIG_ENDIAN); - header = new N3headerNew(); + header = createHeader(); Group.Builder rootGroup = Group.builder(null).setName("").setNcfile(ncfile); header.read(raf, rootGroup, null); @@ -141,10 +146,18 @@ public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask canc } raf.order(RandomAccessFile.BIG_ENDIAN); - header = new N3headerNew(); + header = createHeader(); header.read(raf, rootGroup, null); } + /** + * Create header for reading netcdf file. + * @return + */ + protected N3headerNew createHeader() { + return new N3headerNew(this); + } + ///////////////////////////////////////////////////////////////////////////// // data reading @@ -394,6 +407,9 @@ public String toStringDebug(Object o) { @Override public Object sendIospMessage(Object message) { + if (message instanceof Charset) { + setValueCharset((Charset) message); + } if (null == header) return null; /* @@ -406,6 +422,24 @@ public Object sendIospMessage(Object message) { return super.sendIospMessage(message); } + /** + * Return {@link Charset value charset} if it was defined. Definition of charset + * occurs by sending a charset as a message using the {@link #sendIospMessage} + * method. + * @return {@link Charset value charset} if it was defined. + */ + protected Optional getValueCharset() { + return Optional.ofNullable(valueCharset); + } + + /** + * Define {@link Charset value charset}. + * @param charset may be null. + */ + protected void setValueCharset(Charset charset) { + valueCharset = charset; + } + @Override public String getFileTypeId() { return DataFormatType.NETCDF.getDescription(); diff --git a/cdm/core/src/main/java/ucar/unidata/io/RandomAccessFile.java b/cdm/core/src/main/java/ucar/unidata/io/RandomAccessFile.java index d743772cc8..a004b33df0 100644 --- a/cdm/core/src/main/java/ucar/unidata/io/RandomAccessFile.java +++ b/cdm/core/src/main/java/ucar/unidata/io/RandomAccessFile.java @@ -5,6 +5,7 @@ package ucar.unidata.io; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.stream.Collectors; import ucar.nc2.dataset.DatasetUrl; @@ -1516,9 +1517,21 @@ public final String readUTF() throws IOException { * @throws IOException if an I/O error occurs. */ public String readString(int nbytes) throws IOException { + return readString(nbytes, StandardCharsets.UTF_8); + } + + /** + * Read a String of known length. + * + * @param nbytes number of bytes to reSad + * @param charset the {@link Charset charset} to be used to decode the bytes + * @return String wrapping the bytes. + * @throws IOException if an I/O error occurs. + */ + public String readString(int nbytes, Charset charset) throws IOException { byte[] data = new byte[nbytes]; readFully(data); - return new String(data, StandardCharsets.UTF_8); + return new String(data, charset); } /** @@ -1529,13 +1542,25 @@ public String readString(int nbytes) throws IOException { * @throws IOException if an I/O error occurs. */ public String readStringMax(int nbytes) throws IOException { + return readStringMax(nbytes, StandardCharsets.UTF_8); + } + + /** + * Read a String of max length, zero terminate. + * + * @param nbytes number of bytes to read + * @param charset the {@link Charset charset} to be used to decode the bytes + * @return String wrapping the bytes. + * @throws IOException if an I/O error occurs. + */ + public String readStringMax(int nbytes, Charset charset) throws IOException { byte[] b = new byte[nbytes]; readFully(b); int count; for (count = 0; count < nbytes; count++) if (b[count] == 0) break; - return new String(b, 0, count, StandardCharsets.UTF_8); + return new String(b, 0, count, charset); } // From 8d27ca6a45b61eb30ba40eef944aec830b10fe39 Mon Sep 17 00:00:00 2001 From: Vladislav Fuks Date: Tue, 14 Jan 2020 15:27:51 +0100 Subject: [PATCH 2/7] BUG H5headerNew: fixed definition of unlimited flag before definition of length. Otherwise for unlimited dimension with length == 0 IllegalArgumentException will be thrown. --- .../src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java index 3378097b8a..88e69637b7 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java @@ -840,7 +840,7 @@ private String addDimension(Group.Builder parent, H5Group h5group, String name, Dimension d = h5group.dimMap.get(dimName); // first look in current group if (d == null) { // create if not found - d = Dimension.builder(dimName, length).setIsUnlimited(isUnlimited).build(); + d = Dimension.builder().setName(dimName).setIsUnlimited(isUnlimited).setLength(length).build(); h5group.dimMap.put(dimName, d); h5group.dimList.add(d); parent.addDimension(d); From 5d3a3477be69a43080eb709f4f88cf3997237baa Mon Sep 17 00:00:00 2001 From: Vladislav Fuks Date: Wed, 15 Jan 2020 07:39:17 +0100 Subject: [PATCH 3/7] BUG H5headerNew, H5iospNew, H4header, H4iosp, N3headerNew, N3iospNew: fixed formatting of java-doc comments. --- .../main/java/ucar/nc2/internal/iosp/hdf4/H4header.java | 1 + .../src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java | 4 +++- .../main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java | 3 ++- .../main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java | 3 ++- .../java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java | 7 +++++-- .../java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java | 4 +++- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java index 04e63e1b38..8f88ec33ef 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java @@ -122,6 +122,7 @@ public H4header() { /** * Return defined {@link Charset value charset} that * will be used by reading netcdf file. + * * @return {@link Charset value charset} */ protected Charset getValueCharset() { diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java index c649c73c81..5067511236 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java @@ -12,7 +12,6 @@ import java.nio.charset.Charset; import java.util.List; import java.util.Optional; - import ucar.ma2.Array; import ucar.ma2.ArrayStructure; import ucar.ma2.ArrayStructureBB; @@ -77,6 +76,7 @@ public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) /** * Return header for reading netcdf file. * Create it if it's not already created. + * * @return header for reading netcdf file. */ private H4header getHeader() { @@ -509,6 +509,7 @@ public Object sendIospMessage(Object message) { * Return {@link Charset value charset} if it was defined. Definition of charset * occurs by sending a charset as a message using the {@link #sendIospMessage} * method. + * * @return {@link Charset value charset} if it was defined. */ protected Optional getValueCharset() { @@ -517,6 +518,7 @@ protected Optional getValueCharset() { /** * Define {@link Charset value charset}. + * * @param charset may be null. */ protected void setValueCharset(Charset charset) { diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java index 88e69637b7..0716e90cfd 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java @@ -190,6 +190,7 @@ public static boolean isValidFile(RandomAccessFile raf) throws IOException { /** * Return defined {@link Charset value charset} that * will be used by reading netcdf file. + * * @return {@link Charset value charset} */ protected Charset getValueCharset() { @@ -1219,7 +1220,7 @@ private String convertString(byte[] b, int start, int len) { count++; } return new String(b, start, count - start, valueCharset); // all strings are considered to be UTF-8 - // unicode + // unicode } protected Array convertEnums(Map map, DataType dataType, Array values) { diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java index 41c9868f14..61eba2b28f 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java @@ -9,7 +9,6 @@ import java.nio.ByteOrder; import java.nio.charset.Charset; import java.util.Optional; - import ucar.ma2.Array; import ucar.ma2.ArrayStructure; import ucar.ma2.ArrayStructureBB; @@ -142,6 +141,7 @@ public Object sendIospMessage(Object message) { * Return {@link Charset value charset} if it was defined. Definition of charset * occurs by sending a charset as a message using the {@link #sendIospMessage} * method. + * * @return {@link Charset value charset} if it was defined. */ protected Optional getValueCharset() { @@ -150,6 +150,7 @@ protected Optional getValueCharset() { /** * Define {@link Charset value charset}. + * * @param charset may be null. */ protected void setValueCharset(Charset charset) { diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java index 7570cc2920..7c5dfcb18f 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java @@ -92,6 +92,7 @@ protected N3headerNew(N3iospNew n3iospNew) { /** * Return defined {@link Charset value charset} that * will be used by reading netcdf file. + * * @return {@link Charset value charset} */ protected Charset getValueCharset() { @@ -342,8 +343,9 @@ void read(RandomAccessFile raf, Group.Builder root, Formatter debugOut) throws I /** * Return the byte order that will be used by * {@link #read(RandomAccessFile, Group.Builder, Formatter) reading file}. + * * @return file byte order ({@link RandomAccessFile#BIG_ENDIAN big endian} or - * {@link RandomAccessFile#LITTLE_ENDIAN little endian}) + * {@link RandomAccessFile#LITTLE_ENDIAN little endian}) */ protected int getByteOrder() { return RandomAccessFile.BIG_ENDIAN; @@ -352,9 +354,10 @@ protected int getByteOrder() { /** * Check if the given bytes correspond to * {@link #MAGIC magic bytes} of the header. + * * @param bytes given bytes. * @return true if the given bytes correspond to - * {@link #MAGIC magic bytes} of the header. Otherwise false. + * {@link #MAGIC magic bytes} of the header. Otherwise false. */ protected boolean isMagicBytes(byte[] bytes) { for (int i = 0; i < 3; i++) { diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java index 744a1af274..690aae11fc 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java @@ -7,7 +7,6 @@ import java.nio.charset.Charset; import java.util.Formatter; import java.util.Optional; - import ucar.ma2.Array; import ucar.ma2.ArrayStructureBB; import ucar.ma2.DataType; @@ -152,6 +151,7 @@ public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask canc /** * Create header for reading netcdf file. + * * @return */ protected N3headerNew createHeader() { @@ -426,6 +426,7 @@ public Object sendIospMessage(Object message) { * Return {@link Charset value charset} if it was defined. Definition of charset * occurs by sending a charset as a message using the {@link #sendIospMessage} * method. + * * @return {@link Charset value charset} if it was defined. */ protected Optional getValueCharset() { @@ -434,6 +435,7 @@ protected Optional getValueCharset() { /** * Define {@link Charset value charset}. + * * @param charset may be null. */ protected void setValueCharset(Charset charset) { From de4f6d0d69c6777d083266ee738c00cb36aeab62 Mon Sep 17 00:00:00 2001 From: Vladislav Fuks Date: Wed, 29 Jan 2020 07:50:20 +0100 Subject: [PATCH 4/7] MOD N3headerNew, H4header, H5header: fixed java doc comment for the getValueCharset method. MOD N3iospNew, H4iosp, H5iospNew: added @Nullable annotation for the parameter of the new added setValueCharset method. --- .../src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java | 2 +- .../src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java | 6 ++++-- .../main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java | 2 +- .../main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java | 4 +++- .../java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java | 2 +- .../main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java | 4 +++- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java index 8f88ec33ef..e17d691a84 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java @@ -121,7 +121,7 @@ public H4header() { /** * Return defined {@link Charset value charset} that - * will be used by reading netcdf file. + * will be used by reading HDF4 header. * * @return {@link Charset value charset} */ diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java index 5067511236..5661dbb81c 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java @@ -38,6 +38,8 @@ import ucar.unidata.io.PositioningDataInputStream; import ucar.unidata.io.RandomAccessFile; +import javax.annotation.Nullable; + /** HDF4 iosp */ public class H4iosp extends AbstractIOServiceProvider { private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(H4iosp.class); @@ -77,7 +79,7 @@ public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) * Return header for reading netcdf file. * Create it if it's not already created. * - * @return header for reading netcdf file. + * @return header for reading HDF4 file. */ private H4header getHeader() { if (header == null) { @@ -521,7 +523,7 @@ protected Optional getValueCharset() { * * @param charset may be null. */ - protected void setValueCharset(Charset charset) { + protected void setValueCharset(@Nullable Charset charset) { valueCharset = charset; } } diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java index 0716e90cfd..ff5c9e6191 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java @@ -189,7 +189,7 @@ public static boolean isValidFile(RandomAccessFile raf) throws IOException { /** * Return defined {@link Charset value charset} that - * will be used by reading netcdf file. + * will be used by reading HDF5 header. * * @return {@link Charset value charset} */ diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java index 61eba2b28f..09d121df0d 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java @@ -36,6 +36,8 @@ import ucar.nc2.util.CancelTask; import ucar.unidata.io.RandomAccessFile; +import javax.annotation.Nullable; + /** * HDF5 I/O * @@ -153,7 +155,7 @@ protected Optional getValueCharset() { * * @param charset may be null. */ - protected void setValueCharset(Charset charset) { + protected void setValueCharset(@Nullable Charset charset) { valueCharset = charset; } diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java index 7c5dfcb18f..63c6b111d8 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java @@ -91,7 +91,7 @@ protected N3headerNew(N3iospNew n3iospNew) { /** * Return defined {@link Charset value charset} that - * will be used by reading netcdf file. + * will be used by reading HDF3 header. * * @return {@link Charset value charset} */ diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java index 690aae11fc..550a549116 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java @@ -28,6 +28,8 @@ import ucar.nc2.util.CancelTask; import ucar.unidata.io.RandomAccessFile; +import javax.annotation.Nullable; + /** * Read-only using Builders for immutability. * @@ -438,7 +440,7 @@ protected Optional getValueCharset() { * * @param charset may be null. */ - protected void setValueCharset(Charset charset) { + protected void setValueCharset(@Nullable Charset charset) { valueCharset = charset; } From 8c86aa317c08c00c0c2ccf63ffc2b96f242a2ec9 Mon Sep 17 00:00:00 2001 From: Vladislav Fuks Date: Wed, 29 Jan 2020 08:43:17 +0100 Subject: [PATCH 5/7] MOD N3headerNew, N3iospNew, H4header, H4iosp, H5headerNew, H5iospNew: renamed class member valueCharset to the charset since it is used by reading not only values, but for each string. --- .../ucar/nc2/internal/iosp/hdf4/H4header.java | 38 +++++++++---------- .../ucar/nc2/internal/iosp/hdf4/H4iosp.java | 18 ++++----- .../nc2/internal/iosp/hdf5/H5headerNew.java | 22 +++++------ .../nc2/internal/iosp/hdf5/H5iospNew.java | 18 ++++----- .../internal/iosp/netcdf3/N3headerNew.java | 16 ++++---- .../nc2/internal/iosp/netcdf3/N3iospNew.java | 18 ++++----- 6 files changed, 65 insertions(+), 65 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java index e17d691a84..f3c3bf484d 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java @@ -107,26 +107,26 @@ public static void useHdfEos(boolean val) { private MemTracker memTracker; private PrintWriter debugOut; - private final Charset valueCharset; + private final Charset charset; public H4header() { - valueCharset = StandardCharsets.UTF_8; + charset = StandardCharsets.UTF_8; debugOut = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)); } H4header(H4iosp h4iosp) { - valueCharset = h4iosp.getValueCharset().orElse(StandardCharsets.UTF_8); - debugOut = new PrintWriter(new OutputStreamWriter(System.out, valueCharset)); + charset = h4iosp.getCharset().orElse(StandardCharsets.UTF_8); + debugOut = new PrintWriter(new OutputStreamWriter(System.out, charset)); } /** - * Return defined {@link Charset value charset} that + * Return defined {@link Charset charset} that * will be used by reading HDF4 header. * * @return {@link Charset value charset} */ - protected Charset getValueCharset() { - return valueCharset; + protected Charset getCharset() { + return charset; } public boolean isEos() { @@ -452,11 +452,11 @@ private Attribute makeAttribute(TagVH vh) throws IOException { case 3: case 4: if (nelems == 1) - att = new Attribute(name, raf.readStringMax(size, valueCharset)); + att = new Attribute(name, raf.readStringMax(size, charset)); else { String[] vals = new String[nelems]; for (int i = 0; i < nelems; i++) - vals[i] = raf.readStringMax(size, valueCharset); + vals[i] = raf.readStringMax(size, charset); att = new Attribute(name, Array.factory(DataType.STRING, new int[] {nelems}, vals)); } break; @@ -1162,7 +1162,7 @@ List readChunks(NetcdfFile ncfile) throws IOException { String read() throws IOException { raf.seek(data.offset); - return raf.readString(data.length, valueCharset); + return raf.readString(data.length, charset); } public String toString() { @@ -1662,7 +1662,7 @@ protected void read() throws IOException { major = raf.readInt(); minor = raf.readInt(); release = raf.readInt(); - name = raf.readStringMax(length - 12, valueCharset); + name = raf.readStringMax(length - 12, charset); } public String value() { @@ -1684,7 +1684,7 @@ private class TagText extends Tag { protected void read() throws IOException { raf.seek(offset); - text = raf.readStringMax(length, valueCharset); + text = raf.readStringMax(length, charset); } public String detail() { @@ -1706,7 +1706,7 @@ protected void read() throws IOException { raf.seek(offset); obj_tagno = raf.readShort(); obj_refno = raf.readShort(); - text = raf.readStringMax(length - 4, valueCharset).trim(); + text = raf.readStringMax(length - 4, charset).trim(); } public String detail() { @@ -1863,7 +1863,7 @@ protected void read(int n) throws IOException { int start = 0; for (int i = 0; i < length; i++) { if (b[i] == 0) { - text[count] = new String(b, start, i - start, valueCharset); + text[count] = new String(b, start, i - start, charset); count++; if (count == n) break; @@ -1979,9 +1979,9 @@ protected void read() throws IOException { elem_ref[i] = raf.readShort(); short len = raf.readShort(); - name = raf.readStringMax(len, valueCharset); + name = raf.readStringMax(len, charset); len = raf.readShort(); - className = raf.readStringMax(len, valueCharset); + className = raf.readStringMax(len, charset); extag = raf.readShort(); exref = raf.readShort(); @@ -2055,14 +2055,14 @@ protected void read() throws IOException { fld_name = new String[nfields]; for (int i = 0; i < nfields; i++) { short len = raf.readShort(); - fld_name[i] = raf.readStringMax(len, valueCharset); + fld_name[i] = raf.readStringMax(len, charset); } short len = raf.readShort(); - name = raf.readStringMax(len, valueCharset); + name = raf.readStringMax(len, charset); len = raf.readShort(); - className = raf.readStringMax(len, valueCharset); + className = raf.readStringMax(len, charset); extag = raf.readShort(); exref = raf.readShort(); diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java index 5661dbb81c..b2840c94e0 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java @@ -46,7 +46,7 @@ public class H4iosp extends AbstractIOServiceProvider { private static boolean showLayoutTypes; private H4header header; - private Charset valueCharset; + private Charset charset; @Override public boolean isValidFile(RandomAccessFile raf) throws IOException { @@ -499,7 +499,7 @@ public void reacquire() throws IOException { public Object sendIospMessage(Object message) { if (message instanceof Charset) { - setValueCharset((Charset) message); + setCharset((Charset) message); } if (message.toString().equals("header")) { return getHeader(); @@ -508,22 +508,22 @@ public Object sendIospMessage(Object message) { } /** - * Return {@link Charset value charset} if it was defined. Definition of charset + * Return {@link Charset charset} if it was defined. Definition of charset * occurs by sending a charset as a message using the {@link #sendIospMessage} * method. * - * @return {@link Charset value charset} if it was defined. + * @return {@link Charset charset} if it was defined. */ - protected Optional getValueCharset() { - return Optional.ofNullable(valueCharset); + protected Optional getCharset() { + return Optional.ofNullable(charset); } /** - * Define {@link Charset value charset}. + * Define {@link Charset charset}. * * @param charset may be null. */ - protected void setValueCharset(@Nullable Charset charset) { - valueCharset = charset; + protected void setCharset(@Nullable Charset charset) { + this.charset = charset; } } diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java index ff5c9e6191..59cb5a71ca 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java @@ -178,23 +178,23 @@ public static boolean isValidFile(RandomAccessFile raf) throws IOException { private PrintWriter debugOut; private MemTracker memTracker; - private final Charset valueCharset; + private final Charset charset; H5headerNew(RandomAccessFile myRaf, Group.Builder root, H5iospNew h5iosp) { this.raf = myRaf; this.root = root; this.h5iosp = h5iosp; - valueCharset = h5iosp.getValueCharset().orElse(StandardCharsets.UTF_8); + charset = h5iosp.getCharset().orElse(StandardCharsets.UTF_8); } /** - * Return defined {@link Charset value charset} that + * Return defined {@link Charset charset} that * will be used by reading HDF5 header. * - * @return {@link Charset value charset} + * @return {@link Charset charset} */ - protected Charset getValueCharset() { - return valueCharset; + protected Charset getCharset() { + return charset; } public void read(PrintWriter debugPS) throws IOException { @@ -203,7 +203,7 @@ public void read(PrintWriter debugPS) throws IOException { } else if (debug1 || debugContinueMessage || debugCreationOrder || debugDetail || debugDimensionScales || debugGroupBtree || debugHardLink || debugHeap || debugPos || debugReference || debugTracker || debugV || debugSoftLink || warnings) { - debugOut = new PrintWriter(new OutputStreamWriter(System.out, valueCharset)); + debugOut = new PrintWriter(new OutputStreamWriter(System.out, charset)); } h5objects = new H5objects(this, debugOut, memTracker); @@ -1208,7 +1208,7 @@ private String convertString(byte[] b) { break; count++; } - return new String(b, 0, count, valueCharset); // all strings are considered to be UTF-8 unicode + return new String(b, 0, count, charset); // all strings are considered to be UTF-8 unicode } private String convertString(byte[] b, int start, int len) { @@ -1219,7 +1219,7 @@ private String convertString(byte[] b, int start, int len) { break; count++; } - return new String(b, start, count - start, valueCharset); // all strings are considered to be UTF-8 + return new String(b, start, count - start, charset); // all strings are considered to be UTF-8 // unicode } @@ -2117,7 +2117,7 @@ String readHeapString(long heapIdAddress) throws IOException { if (ho.dataSize > 1000 * 1000) return String.format("Bad HeapObject.dataSize=%s", ho); raf.seek(ho.dataPos); - return raf.readString((int) ho.dataSize, valueCharset); + return raf.readString((int) ho.dataSize, charset); } /** @@ -2134,7 +2134,7 @@ String readHeapString(ByteBuffer bb, int pos) throws IOException { if (ho == null) throw new IllegalStateException("Cant find Heap Object,heapId=" + heapId); raf.seek(ho.dataPos); - return raf.readString((int) ho.dataSize, valueCharset); + return raf.readString((int) ho.dataSize, charset); } Array readHeapVlen(ByteBuffer bb, int pos, DataType dataType, int endian) throws IOException, InvalidRangeException { diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java index 09d121df0d..6ff814379e 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java @@ -109,7 +109,7 @@ public boolean isBuilder() { private H5headerNew header; private boolean isEos; boolean includeOriginalAttributes; - private Charset valueCharset; + private Charset charset; @Override public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException { @@ -134,29 +134,29 @@ public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask canc @Override public Object sendIospMessage(Object message) { if (message instanceof Charset) { - setValueCharset((Charset) message); + setCharset((Charset) message); } return super.sendIospMessage(message); } /** - * Return {@link Charset value charset} if it was defined. Definition of charset + * Return {@link Charset charset} if it was defined. Definition of charset * occurs by sending a charset as a message using the {@link #sendIospMessage} * method. * - * @return {@link Charset value charset} if it was defined. + * @return {@link Charset charset} if it was defined. */ - protected Optional getValueCharset() { - return Optional.ofNullable(valueCharset); + protected Optional getCharset() { + return Optional.ofNullable(charset); } /** - * Define {@link Charset value charset}. + * Define {@link Charset charset}. * * @param charset may be null. */ - protected void setValueCharset(@Nullable Charset charset) { - valueCharset = charset; + protected void setCharset(@Nullable Charset charset) { + this.charset = charset; } @Override diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java index 63c6b111d8..7f0f33f04f 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java @@ -71,7 +71,7 @@ static class Vinfo { private long dataStart = Long.MAX_VALUE; // where the data starts - private final Charset valueCharset; + private final Charset charset; /* * Notes: @@ -82,21 +82,21 @@ static class Vinfo { */ public N3headerNew() { - valueCharset = StandardCharsets.UTF_8; + charset = StandardCharsets.UTF_8; } protected N3headerNew(N3iospNew n3iospNew) { - valueCharset = n3iospNew.getValueCharset().orElse(StandardCharsets.UTF_8); + charset = n3iospNew.getCharset().orElse(StandardCharsets.UTF_8); } /** - * Return defined {@link Charset value charset} that + * Return defined {@link Charset charset} that * will be used by reading HDF3 header. * - * @return {@link Charset value charset} + * @return {@link Charset charset} */ - protected Charset getValueCharset() { - return valueCharset; + protected Charset getCharset() { + return charset; } /** @@ -568,7 +568,7 @@ private String readString() throws IOException { count++; } - return new String(b, 0, count, valueCharset); // all strings are considered to be UTF-8 unicode. + return new String(b, 0, count, charset); // all strings are considered to be UTF-8 unicode. } // skip to a 4 byte boundary in the file diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java index 550a549116..98bef0842d 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java @@ -81,7 +81,7 @@ public class N3iospNew extends AbstractIOServiceProvider implements IOServicePro protected long lastModified; // used by sync protected boolean debug, debugRecord, debugRead; - private Charset valueCharset; + private Charset charset; @Override public boolean isValidFile(ucar.unidata.io.RandomAccessFile raf) throws IOException { @@ -410,7 +410,7 @@ public String toStringDebug(Object o) { @Override public Object sendIospMessage(Object message) { if (message instanceof Charset) { - setValueCharset((Charset) message); + setCharset((Charset) message); } if (null == header) return null; @@ -425,23 +425,23 @@ public Object sendIospMessage(Object message) { } /** - * Return {@link Charset value charset} if it was defined. Definition of charset + * Return {@link Charset charset} if it was defined. Definition of charset * occurs by sending a charset as a message using the {@link #sendIospMessage} * method. * - * @return {@link Charset value charset} if it was defined. + * @return {@link Charset charset} if it was defined. */ - protected Optional getValueCharset() { - return Optional.ofNullable(valueCharset); + protected Optional getCharset() { + return Optional.ofNullable(charset); } /** - * Define {@link Charset value charset}. + * Define {@link Charset charset}. * * @param charset may be null. */ - protected void setValueCharset(@Nullable Charset charset) { - valueCharset = charset; + protected void setCharset(@Nullable Charset charset) { + this.charset = charset; } @Override From 504f69564ff3453a93a9f3bc89ec08ba3831fef0 Mon Sep 17 00:00:00 2001 From: Vladislav Fuks Date: Wed, 29 Jan 2020 09:03:08 +0100 Subject: [PATCH 6/7] MOD N3iospNew, H4iosp, H5headerNew, H5iospNew: fixed some code violations (spotlessApply). --- cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java | 1 - .../src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java | 2 +- .../src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java | 1 - .../src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java index b2840c94e0..c75ee8087d 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java @@ -37,7 +37,6 @@ import ucar.nc2.util.IO; import ucar.unidata.io.PositioningDataInputStream; import ucar.unidata.io.RandomAccessFile; - import javax.annotation.Nullable; /** HDF4 iosp */ diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java index 59cb5a71ca..09ba3969dc 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java @@ -1220,7 +1220,7 @@ private String convertString(byte[] b, int start, int len) { count++; } return new String(b, start, count - start, charset); // all strings are considered to be UTF-8 - // unicode + // unicode } protected Array convertEnums(Map map, DataType dataType, Array values) { diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java index 6ff814379e..676ea4684f 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java @@ -35,7 +35,6 @@ import ucar.nc2.time.CalendarDate; import ucar.nc2.util.CancelTask; import ucar.unidata.io.RandomAccessFile; - import javax.annotation.Nullable; /** diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java index 98bef0842d..72c5f16e6f 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java @@ -27,7 +27,6 @@ import ucar.nc2.internal.iosp.netcdf3.N3headerNew.Vinfo; import ucar.nc2.util.CancelTask; import ucar.unidata.io.RandomAccessFile; - import javax.annotation.Nullable; /** From 27df136965f06bf6f358a5bc7ca0575a7c87b547 Mon Sep 17 00:00:00 2001 From: Vladislav Fuks Date: Thu, 13 Feb 2020 15:33:45 +0100 Subject: [PATCH 7/7] MOD N3iospNew, N3headerNew: renamed "charset" to the "valueCharset" since it is applied only by reading attribute values. MOD H4iosp, H4header: renamed "charset" to the "valueCharset" since it is applied only by reading attribute values, and also text of the TagText, TagAnnotate and TagTextN. MOD H5iospNew, H5headerNew: renamed "charset" to the "valueCharset" since it is applied only by reading attribute values. --- .../ucar/nc2/internal/iosp/hdf4/H4header.java | 38 +++++++++---------- .../ucar/nc2/internal/iosp/hdf4/H4iosp.java | 18 ++++----- .../nc2/internal/iosp/hdf5/H5headerNew.java | 22 +++++------ .../nc2/internal/iosp/hdf5/H5iospNew.java | 18 ++++----- .../internal/iosp/netcdf3/N3headerNew.java | 18 +++++---- .../nc2/internal/iosp/netcdf3/N3iospNew.java | 18 ++++----- 6 files changed, 68 insertions(+), 64 deletions(-) diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java index f3c3bf484d..7241e70786 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4header.java @@ -107,26 +107,26 @@ public static void useHdfEos(boolean val) { private MemTracker memTracker; private PrintWriter debugOut; - private final Charset charset; + private final Charset valueCharset; public H4header() { - charset = StandardCharsets.UTF_8; + valueCharset = StandardCharsets.UTF_8; debugOut = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)); } H4header(H4iosp h4iosp) { - charset = h4iosp.getCharset().orElse(StandardCharsets.UTF_8); - debugOut = new PrintWriter(new OutputStreamWriter(System.out, charset)); + valueCharset = h4iosp.getValueCharset().orElse(StandardCharsets.UTF_8); + debugOut = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)); } /** - * Return defined {@link Charset charset} that + * Return defined {@link Charset value charset} that * will be used by reading HDF4 header. * * @return {@link Charset value charset} */ - protected Charset getCharset() { - return charset; + protected Charset getValueCharset() { + return valueCharset; } public boolean isEos() { @@ -452,11 +452,11 @@ private Attribute makeAttribute(TagVH vh) throws IOException { case 3: case 4: if (nelems == 1) - att = new Attribute(name, raf.readStringMax(size, charset)); + att = new Attribute(name, raf.readStringMax(size, valueCharset)); else { String[] vals = new String[nelems]; for (int i = 0; i < nelems; i++) - vals[i] = raf.readStringMax(size, charset); + vals[i] = raf.readStringMax(size, valueCharset); att = new Attribute(name, Array.factory(DataType.STRING, new int[] {nelems}, vals)); } break; @@ -1162,7 +1162,7 @@ List readChunks(NetcdfFile ncfile) throws IOException { String read() throws IOException { raf.seek(data.offset); - return raf.readString(data.length, charset); + return raf.readString(data.length, valueCharset); } public String toString() { @@ -1662,7 +1662,7 @@ protected void read() throws IOException { major = raf.readInt(); minor = raf.readInt(); release = raf.readInt(); - name = raf.readStringMax(length - 12, charset); + name = raf.readStringMax(length - 12); } public String value() { @@ -1684,7 +1684,7 @@ private class TagText extends Tag { protected void read() throws IOException { raf.seek(offset); - text = raf.readStringMax(length, charset); + text = raf.readStringMax(length, valueCharset); } public String detail() { @@ -1706,7 +1706,7 @@ protected void read() throws IOException { raf.seek(offset); obj_tagno = raf.readShort(); obj_refno = raf.readShort(); - text = raf.readStringMax(length - 4, charset).trim(); + text = raf.readStringMax(length - 4, valueCharset).trim(); } public String detail() { @@ -1863,7 +1863,7 @@ protected void read(int n) throws IOException { int start = 0; for (int i = 0; i < length; i++) { if (b[i] == 0) { - text[count] = new String(b, start, i - start, charset); + text[count] = new String(b, start, i - start, valueCharset); count++; if (count == n) break; @@ -1979,9 +1979,9 @@ protected void read() throws IOException { elem_ref[i] = raf.readShort(); short len = raf.readShort(); - name = raf.readStringMax(len, charset); + name = raf.readStringMax(len); len = raf.readShort(); - className = raf.readStringMax(len, charset); + className = raf.readStringMax(len); extag = raf.readShort(); exref = raf.readShort(); @@ -2055,14 +2055,14 @@ protected void read() throws IOException { fld_name = new String[nfields]; for (int i = 0; i < nfields; i++) { short len = raf.readShort(); - fld_name[i] = raf.readStringMax(len, charset); + fld_name[i] = raf.readStringMax(len); } short len = raf.readShort(); - name = raf.readStringMax(len, charset); + name = raf.readStringMax(len); len = raf.readShort(); - className = raf.readStringMax(len, charset); + className = raf.readStringMax(len); extag = raf.readShort(); exref = raf.readShort(); diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java index c75ee8087d..1de43f1688 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf4/H4iosp.java @@ -45,7 +45,7 @@ public class H4iosp extends AbstractIOServiceProvider { private static boolean showLayoutTypes; private H4header header; - private Charset charset; + private Charset valueCharset; @Override public boolean isValidFile(RandomAccessFile raf) throws IOException { @@ -498,7 +498,7 @@ public void reacquire() throws IOException { public Object sendIospMessage(Object message) { if (message instanceof Charset) { - setCharset((Charset) message); + setValueCharset((Charset) message); } if (message.toString().equals("header")) { return getHeader(); @@ -507,22 +507,22 @@ public Object sendIospMessage(Object message) { } /** - * Return {@link Charset charset} if it was defined. Definition of charset + * Return {@link Charset value charset} if it was defined. Definition of charset * occurs by sending a charset as a message using the {@link #sendIospMessage} * method. * - * @return {@link Charset charset} if it was defined. + * @return {@link Charset value charset} if it was defined. */ - protected Optional getCharset() { - return Optional.ofNullable(charset); + protected Optional getValueCharset() { + return Optional.ofNullable(valueCharset); } /** - * Define {@link Charset charset}. + * Define {@link Charset value charset}. * * @param charset may be null. */ - protected void setCharset(@Nullable Charset charset) { - this.charset = charset; + protected void setValueCharset(@Nullable Charset charset) { + this.valueCharset = charset; } } diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java index f671328d1b..ba07fdb37e 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java @@ -178,23 +178,23 @@ public static boolean isValidFile(RandomAccessFile raf) throws IOException { private PrintWriter debugOut; private MemTracker memTracker; - private final Charset charset; + private final Charset valueCharset; H5headerNew(RandomAccessFile myRaf, Group.Builder root, H5iospNew h5iosp) { this.raf = myRaf; this.root = root; this.h5iosp = h5iosp; - charset = h5iosp.getCharset().orElse(StandardCharsets.UTF_8); + valueCharset = h5iosp.getValueCharset().orElse(StandardCharsets.UTF_8); } /** - * Return defined {@link Charset charset} that + * Return defined {@link Charset value charset} that * will be used by reading HDF5 header. * * @return {@link Charset charset} */ - protected Charset getCharset() { - return charset; + protected Charset getValueCharset() { + return valueCharset; } public void read(PrintWriter debugPS) throws IOException { @@ -203,7 +203,7 @@ public void read(PrintWriter debugPS) throws IOException { } else if (debug1 || debugContinueMessage || debugCreationOrder || debugDetail || debugDimensionScales || debugGroupBtree || debugHardLink || debugHeap || debugPos || debugReference || debugTracker || debugV || debugSoftLink || warnings) { - debugOut = new PrintWriter(new OutputStreamWriter(System.out, charset)); + debugOut = new PrintWriter(new OutputStreamWriter(System.out)); } h5objects = new H5objects(this, debugOut, memTracker); @@ -1208,7 +1208,7 @@ private String convertString(byte[] b) { break; count++; } - return new String(b, 0, count, charset); // all strings are considered to be UTF-8 unicode + return new String(b, 0, count, valueCharset); // all strings are considered to be UTF-8 unicode } private String convertString(byte[] b, int start, int len) { @@ -1219,8 +1219,8 @@ private String convertString(byte[] b, int start, int len) { break; count++; } - return new String(b, start, count - start, charset); // all strings are considered to be UTF-8 - // unicode + return new String(b, start, count - start, valueCharset); // all strings are considered to be UTF-8 + // unicode } protected Array convertEnums(Map map, DataType dataType, Array values) { @@ -2118,7 +2118,7 @@ String readHeapString(long heapIdAddress) throws IOException { if (ho.dataSize > 1000 * 1000) return String.format("Bad HeapObject.dataSize=%s", ho); raf.seek(ho.dataPos); - return raf.readString((int) ho.dataSize, charset); + return raf.readString((int) ho.dataSize, valueCharset); } /** @@ -2135,7 +2135,7 @@ String readHeapString(ByteBuffer bb, int pos) throws IOException { if (ho == null) throw new IllegalStateException("Cant find Heap Object,heapId=" + heapId); raf.seek(ho.dataPos); - return raf.readString((int) ho.dataSize, charset); + return raf.readString((int) ho.dataSize, valueCharset); } Array readHeapVlen(ByteBuffer bb, int pos, DataType dataType, int endian) throws IOException, InvalidRangeException { diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java index 676ea4684f..3e5a0e5a1d 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5iospNew.java @@ -108,7 +108,7 @@ public boolean isBuilder() { private H5headerNew header; private boolean isEos; boolean includeOriginalAttributes; - private Charset charset; + private Charset valueCharset; @Override public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException { @@ -133,29 +133,29 @@ public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask canc @Override public Object sendIospMessage(Object message) { if (message instanceof Charset) { - setCharset((Charset) message); + setValueCharset((Charset) message); } return super.sendIospMessage(message); } /** - * Return {@link Charset charset} if it was defined. Definition of charset + * Return {@link Charset value charset} if it was defined. Definition of charset * occurs by sending a charset as a message using the {@link #sendIospMessage} * method. * - * @return {@link Charset charset} if it was defined. + * @return {@link Charset value charset} if it was defined. */ - protected Optional getCharset() { - return Optional.ofNullable(charset); + protected Optional getValueCharset() { + return Optional.ofNullable(valueCharset); } /** - * Define {@link Charset charset}. + * Define {@link Charset value charset}. * * @param charset may be null. */ - protected void setCharset(@Nullable Charset charset) { - this.charset = charset; + protected void setValueCharset(@Nullable Charset charset) { + this.valueCharset = charset; } @Override diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java index 7f0f33f04f..9584f19f2e 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerNew.java @@ -71,7 +71,7 @@ static class Vinfo { private long dataStart = Long.MAX_VALUE; // where the data starts - private final Charset charset; + private final Charset valueCharset; /* * Notes: @@ -82,21 +82,21 @@ static class Vinfo { */ public N3headerNew() { - charset = StandardCharsets.UTF_8; + valueCharset = StandardCharsets.UTF_8; } protected N3headerNew(N3iospNew n3iospNew) { - charset = n3iospNew.getCharset().orElse(StandardCharsets.UTF_8); + valueCharset = n3iospNew.getValueCharset().orElse(StandardCharsets.UTF_8); } /** - * Return defined {@link Charset charset} that + * Return defined {@link Charset value charset} that * will be used by reading HDF3 header. * * @return {@link Charset charset} */ - protected Charset getCharset() { - return charset; + protected Charset getValueCharset() { + return valueCharset; } /** @@ -470,7 +470,7 @@ private int readAtts(AttributeContainer atts, Formatter fout) throws IOException if (type == 2) { if (fout != null) fout.format(" begin read String val pos= %d%n", raf.getFilePointer()); - String val = readString(); + String val = readString(getValueCharset()); if (val == null) val = ""; if (fout != null) @@ -552,6 +552,10 @@ private int readAttributeValue(DataType type, IndexIterator ii) throws IOExcepti // read a string = (nelems, byte array), then skip to 4 byte boundary private String readString() throws IOException { + return readString(StandardCharsets.UTF_8); + } + + private String readString(Charset charset) throws IOException { int nelems = raf.readInt(); byte[] b = new byte[nelems]; raf.readFully(b); diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java index 72c5f16e6f..b3619d45d8 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3iospNew.java @@ -80,7 +80,7 @@ public class N3iospNew extends AbstractIOServiceProvider implements IOServicePro protected long lastModified; // used by sync protected boolean debug, debugRecord, debugRead; - private Charset charset; + private Charset valueCharset; @Override public boolean isValidFile(ucar.unidata.io.RandomAccessFile raf) throws IOException { @@ -409,7 +409,7 @@ public String toStringDebug(Object o) { @Override public Object sendIospMessage(Object message) { if (message instanceof Charset) { - setCharset((Charset) message); + setValueCharset((Charset) message); } if (null == header) return null; @@ -424,23 +424,23 @@ public Object sendIospMessage(Object message) { } /** - * Return {@link Charset charset} if it was defined. Definition of charset + * Return {@link Charset value charset} if it was defined. Definition of charset * occurs by sending a charset as a message using the {@link #sendIospMessage} * method. * - * @return {@link Charset charset} if it was defined. + * @return {@link Charset value charset} if it was defined. */ - protected Optional getCharset() { - return Optional.ofNullable(charset); + protected Optional getValueCharset() { + return Optional.ofNullable(valueCharset); } /** - * Define {@link Charset charset}. + * Define {@link Charset value charset}. * * @param charset may be null. */ - protected void setCharset(@Nullable Charset charset) { - this.charset = charset; + protected void setValueCharset(@Nullable Charset charset) { + this.valueCharset = charset; } @Override