Commit a36c05d60d6cd2d93fcbe03d2858c2813555ca3b

Authored by Nathanael Jourdane
1 parent e6fb239b
Exists in master and in 1 other branch b6.0.X

Fix Sonar issues.

src/main/java/eu/omp/irap/vespa/votable/controller/VOTableController.java
... ... @@ -54,7 +54,7 @@ public class VOTableController implements VOTableViewListener {
54 54 * Constructor of VOTableController
55 55 */
56 56 public VOTableController() {
57   - // TODO Auto-generated constructor stub
  57 + /* Subclasses initializes their own attributes, we don't want to initialize them twice. */
58 58 }
59 59  
60 60 public VOTableController(String voTablePath) {
... ... @@ -91,7 +91,6 @@ public class VOTableController implements VOTableViewListener {
91 91 * @throws CantDisplayVOTableException If the VOTable can not be filled.
92 92 * @throws CantSendQueryException
93 93 */
94   - // TODO: can't fill table exception
95 94 public void readTable() throws CantGetVOTableException {
96 95 if (voTablePath == null) {
97 96 voTablePath = VOTableController.downloadVOTable(targetURL, query);
... ...
src/main/java/eu/omp/irap/vespa/votable/controller/VOTableParser.java
... ... @@ -20,7 +20,6 @@ import java.io.File;
20 20 import java.io.IOException;
21 21 import java.util.HashMap;
22 22 import java.util.Map;
23   -import java.util.logging.Logger;
24 23  
25 24 import javax.xml.bind.JAXBContext;
26 25 import javax.xml.bind.JAXBException;
... ... @@ -34,9 +33,6 @@ import eu.omp.irap.vespa.votable.utils.XMLUtils;
34 33 */
35 34 public final class VOTableParser {
36 35  
37   - /** The logger for the class VOTableParser. */
38   - private static final Logger logger = Logger.getLogger(VOTableParser.class.getName());
39   -
40 36 /** The path of the VOTable to verify the VOTable XML file. */
41 37 private static final String VOTABLE_SHEMA = "http://www.ivoa.net/xml/VOTable/v";
42 38  
... ...
src/main/java/eu/omp/irap/vespa/votable/utils/Debug.java
... ... @@ -34,6 +34,9 @@ public class Debug {
34 34 private static final Logger logger = Logger.getLogger(Debug.class.getName());
35 35  
36 36  
  37 + private Debug() {
  38 + }
  39 +
37 40 /**
38 41 * Print the specified object in JSON format in a file on the temporary directory.
39 42 *
... ...
src/main/java/eu/omp/irap/vespa/votable/utils/Network.java
... ... @@ -55,7 +55,7 @@ public class Network {
55 55 public static JsonObject readJson(String query) throws CantSendQueryException {
56 56 try (BufferedReader reader = new BufferedReader(
57 57 new InputStreamReader(new URL(query).openStream()))) {
58   - StringBuffer buffer = new StringBuffer();
  58 + StringBuilder buffer = new StringBuilder();
59 59 int read;
60 60 char[] chars = new char[1024];
61 61 while ((read = reader.read(chars)) != -1) {
... ... @@ -63,7 +63,7 @@ public class Network {
63 63 }
64 64 return new JsonParser().parse(buffer.toString()).getAsJsonObject();
65 65 } catch (IOException e) {
66   - throw new CantSendQueryException("Can not send the Json query " + query);
  66 + throw new CantSendQueryException("Can not send the Json query " + query, e);
67 67 }
68 68 }
69 69  
... ... @@ -87,8 +87,7 @@ public class Network {
87 87 * @return A string builder containing the result of the query.
88 88 * @throws CantSendQueryException If the query can not be sent.
89 89 */
90   - private static StringBuilder sendGet(String url)
91   - throws CantSendQueryException {
  90 + private static StringBuilder sendGet(String url) throws CantSendQueryException {
92 91 String inputLine;
93 92 StringBuilder response = new StringBuilder();
94 93 URL obj;
... ... @@ -143,9 +142,7 @@ public class Network {
143 142 return response;
144 143 }
145 144  
146   - public static String buildQuery(String url, Map<String, String> parameters)
147   - throws IllegalArgumentException {
148   -
  145 + public static String buildQuery(String url, Map<String, String> parameters) {
149 146 StringJoiner paramJoiner = new StringJoiner("&");
150 147 for (Map.Entry<String, String> param : parameters.entrySet()) {
151 148 try {
... ... @@ -154,13 +151,11 @@ public class Network {
154 151 .replace(".", "%2E").replace("-", "%2D").replace("*", "%2A")
155 152 .replace("_", "%5F");
156 153 paramJoiner.add(param.getKey() + "=" + value);
157   -
158 154 } catch (UnsupportedEncodingException e) {
159 155 throw new IllegalArgumentException("Unsupported Encoding on key=" + param.getKey()
160 156 + " and value=" + param.getValue(), e);
161 157 }
162 158 }
163   -
164 159 return url + "?" + paramJoiner;
165 160 }
166 161 }
... ...
src/main/java/eu/omp/irap/vespa/votable/utils/XMLUtils.java
... ... @@ -19,7 +19,6 @@ package eu.omp.irap.vespa.votable.utils;
19 19 import java.io.File;
20 20 import java.io.IOException;
21 21 import java.util.Map;
22   -import java.util.logging.Logger;
23 22  
24 23 import javax.xml.parsers.DocumentBuilderFactory;
25 24 import javax.xml.parsers.ParserConfigurationException;
... ... @@ -39,9 +38,8 @@ import org.xml.sax.SAXException;
39 38 */
40 39 public class XMLUtils {
41 40  
42   - /** The logger for the class XMLUtils. */
43   - private static final Logger logger = Logger.getLogger(XMLUtils.class.getName());
44   -
  41 + private XMLUtils() {
  42 + }
45 43  
46 44 public static void changeRootAttributes(String xmlPath, Map<String, String> attributes)
47 45 throws IOException {
... ...
src/main/java/eu/omp/irap/vespa/votable/view/VOTableView.java
... ... @@ -28,7 +28,6 @@ import javax.swing.table.DefaultTableModel;
28 28 import javax.swing.table.TableModel;
29 29 import javax.swing.table.TableRowSorter;
30 30  
31   -import eu.omp.irap.vespa.votable.utils.Debug;
32 31 import eu.omp.irap.vespa.votable.votabledata.VOTableData;
33 32  
34 33 /**
... ... @@ -89,8 +88,6 @@ public class VOTableView extends JPanel implements TableModelListener {
89 88 public void fillTable(VOTableData data) {
90 89 String[] columns = data.getColumnsName();
91 90 Object[][] rows = data.getDataArray();
92   - Debug.writeObject("tableColumns", columns);
93   - Debug.writeObject("tableData", rows);
94 91 tableData.setDataVector(rows, columns);
95 92  
96 93 if (rows.length != 0) {
... ...
src/main/java/eu/omp/irap/vespa/votable/votabledata/Binary2StreamParser.java
... ... @@ -16,6 +16,7 @@
16 16  
17 17 package eu.omp.irap.vespa.votable.votabledata;
18 18  
  19 +import java.util.ArrayList;
19 20 import java.util.List;
20 21 import java.util.logging.Logger;
21 22  
... ... @@ -45,6 +46,6 @@ public class Binary2StreamParser implements DataParser {
45 46 @Override
46 47 public List<Object[]> parse() {
47 48 Binary2StreamParser.logger.info("Parsing data from Binary2Stream stream...");
48   - return null;
  49 + return new ArrayList<>();
49 50 }
50 51 }
... ...
src/main/java/eu/omp/irap/vespa/votable/votabledata/BinaryStreamParser.java
... ... @@ -63,9 +63,7 @@ public final class BinaryStreamParser implements DataParser {
63 63 public BinaryStreamParser(Stream voStream, List<Field> fieldsNodes) {
64 64 cursor = 0;
65 65 this.fieldsNodes = fieldsNodes;
66   - Debug.writeObject("voStream", voStream.getValue());
67 66 String strStream = voStream.getValue().replaceAll("(\\r|\\n)", "");
68   - Debug.writeObject("strStream", strStream);
69 67 stream = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(strStream));
70 68 }
71 69  
... ... @@ -77,32 +75,34 @@ public final class BinaryStreamParser implements DataParser {
77 75 * @return The size of the block, in bytes.
78 76 */
79 77 private static int getBlockSize(DataType dataType) {
  78 + int blockSize;
80 79 switch (dataType) {
81 80 case BOOLEAN:
82   - return 1;
83 81 case UNSIGNED_BYTE:
84   - return 1;
85   - case SHORT:
86   - return 2;
87   - case INT:
88   - return 4;
89   - case LONG:
90   - return 8;
91 82 case CHAR:
92   - return 1;
  83 + blockSize = 1;
  84 + break;
  85 + case SHORT:
93 86 case UNICODE_CHAR:
94   - return 2;
  87 + blockSize = 2;
  88 + break;
  89 + case INT:
95 90 case FLOAT:
96   - return 4;
  91 + blockSize = 4;
  92 + break;
  93 + case LONG:
97 94 case DOUBLE:
98   - return 8;
99 95 case FLOAT_COMPLEX:
100   - return 8;
  96 + blockSize = 8;
  97 + break;
101 98 case DOUBLE_COMPLEX:
102   - return 16;
  99 + blockSize = 16;
  100 + break;
103 101 default:
104   - return 0;
  102 + blockSize = 0;
  103 + break;
105 104 }
  105 + return blockSize;
106 106 }
107 107  
108 108 /**
... ... @@ -112,8 +112,7 @@ public final class BinaryStreamParser implements DataParser {
112 112 * @throws BufferUnderflowException Can not get the array size because there is no bytes to read
113 113 * in the stream.
114 114 */
115   - private int getRowSize(Field column)
116   - throws BufferUnderflowException {
  115 + private int getRowSize(Field column) {
117 116 DataType dataType = column.getDatatype();
118 117 int blockSize = getBlockSize(dataType);
119 118 int arraySize;
... ... @@ -147,15 +146,11 @@ public final class BinaryStreamParser implements DataParser {
147 146 int nValue = 0;
148 147 while (stream.hasRemaining()) {
149 148 int colId = nValue % nbColumns;
150   - // logger.info("row: " + (nValue / nbColumns + 1) + " ; col: " + (colId + 1) + "/"
151   - // + nbColumns);
152 149 Field column = fieldsNodes.get(colId);
153 150  
154 151 rowSize = getRowSize(column);
155 152  
156   - // if (arraySize == 0) {
157   - // continue;
158   - // }
  153 + // May be useful: if arraySize == 0, continue
159 154  
160 155 if (colId == 0) {
161 156 row = new Object[nbColumns];
... ...
src/main/java/eu/omp/irap/vespa/votable/votabledata/FitsParser.java
... ... @@ -16,6 +16,7 @@
16 16  
17 17 package eu.omp.irap.vespa.votable.votabledata;
18 18  
  19 +import java.util.ArrayList;
19 20 import java.util.List;
20 21 import java.util.logging.Logger;
21 22  
... ... @@ -47,6 +48,6 @@ public class FitsParser implements DataParser {
47 48 @Override
48 49 public List<Object[]> parse() {
49 50 FitsParser.logger.info("Parsing data from FITS stream...");
50   - return null;
  51 + return new ArrayList<>();
51 52 }
52 53 }
... ...
src/main/java/eu/omp/irap/vespa/votable/votabledata/TableDataParser.java
... ... @@ -16,6 +16,7 @@
16 16  
17 17 package eu.omp.irap.vespa.votable.votabledata;
18 18  
  19 +import java.util.ArrayList;
19 20 import java.util.List;
20 21 import java.util.logging.Logger;
21 22  
... ... @@ -47,6 +48,6 @@ public class TableDataParser implements DataParser {
47 48 @Override
48 49 public List<Object[]> parse() {
49 50 TableDataParser.logger.info("Parsing data in FITS stream...");
50   - return null;
  51 + return new ArrayList<>();
51 52 }
52 53 }
... ...
src/main/java/eu/omp/irap/vespa/votable/votabledata/VOTableDataParser.java
... ... @@ -74,7 +74,7 @@ public class VOTableDataParser {
74 74 }
75 75  
76 76 public VOTableData parseData() throws CantGetVOTableException {
77   - DataParser parser = null;
  77 + DataParser parser;
78 78 if (dataNode.getBINARY() != null) {
79 79 parser = new BinaryStreamParser(dataNode.getBINARY().getSTREAM(), fieldsNodes);
80 80 } else if (dataNode.getBINARY2() != null) {
... ... @@ -83,6 +83,8 @@ public class VOTableDataParser {
83 83 parser = new TableDataParser(dataNode.getTABLEDATA(), fieldsNodes);
84 84 } else if (dataNode.getFITS() != null) {
85 85 parser = new FitsParser(dataNode.getFITS(), fieldsNodes);
  86 + } else {
  87 + throw new CantGetVOTableException("Can not locate the data in the VOTable.");
86 88 }
87 89 data.setData(parser.parse());
88 90  
... ...