Commit 041cc39421d33534a18b932fcca5a9dd371e961b
1 parent
18fad48e
Exists in
master
improve utils package hierarchy.
Showing
3 changed files
with
62 additions
and
33 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Const.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Consts.java
... | ... | @@ -21,7 +21,7 @@ package eu.omp.irap.vespa.epntapclient.votable.utils; |
21 | 21 | * |
22 | 22 | * @author N. Jourdane |
23 | 23 | */ |
24 | -public class Const { | |
24 | +public class Consts { | |
25 | 25 | |
26 | 26 | /** The character set used (for http requests, writing in files, etc.). */ |
27 | 27 | public static final String ENCODING = "UTF-8"; |
... | ... | @@ -38,6 +38,6 @@ public class Const { |
38 | 38 | |
39 | 39 | |
40 | 40 | /** Constructor to hide the implicit public one. */ |
41 | - private Const() { | |
41 | + private Consts() { | |
42 | 42 | } |
43 | 43 | } | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Debug.java
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
1 | +/* | |
2 | + * This file is a part of EpnTAPClient. | |
3 | + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. | |
4 | + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 | |
5 | + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. | |
6 | + * | |
7 | + * This program is free software: you can | |
8 | + * redistribute it and/or modify it under the terms of the GNU General Public License as published | |
9 | + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later | |
10 | + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY | |
11 | + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
12 | + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of | |
13 | + * the GNU General Public License along with this program. If not, see | |
14 | + * <http://www.gnu.org/licenses/>. | |
15 | + */ | |
16 | + | |
17 | +package eu.omp.irap.vespa.epntapclient.votable.utils; | |
18 | + | |
19 | +import java.io.FileWriter; | |
20 | +import java.io.IOException; | |
21 | +import java.util.logging.Logger; | |
22 | + | |
23 | +import com.google.gson.Gson; | |
24 | +import com.google.gson.GsonBuilder; | |
25 | + | |
26 | +/** | |
27 | + * @author N. Jourdane | |
28 | + */ | |
29 | +public class Debug { | |
30 | + | |
31 | + /** The logger for the class Debug. */ | |
32 | + private static final Logger logger = Logger.getLogger(Debug.class.getName()); | |
33 | + | |
34 | + | |
35 | + /** | |
36 | + * Print the specified object in JSON format in a file on the temporary directory. | |
37 | + * | |
38 | + * @param title The name of the file. | |
39 | + * @param obj the object to print in a file. | |
40 | + * @return The path of the file. | |
41 | + */ | |
42 | + public static String printObject(String title, Object obj) { | |
43 | + Gson gson = new GsonBuilder().setPrettyPrinting().create(); | |
44 | + String json = gson.toJson(obj); | |
45 | + String path = Consts.TMP_DIR + "/" + title + ".json"; | |
46 | + try (FileWriter writer = new FileWriter(path)) { | |
47 | + writer.write(json); | |
48 | + | |
49 | + } catch (IOException e) { | |
50 | + Debug.logger.warning("Can not print in the file " + path + e); | |
51 | + } | |
52 | + Debug.logger.info("A json file representing " + title + " (" + obj.getClass().getName() | |
53 | + + ") has been created on " + path); | |
54 | + | |
55 | + return path; | |
56 | + } | |
57 | +} | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Utils.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Strings.java
... | ... | @@ -16,24 +16,19 @@ |
16 | 16 | |
17 | 17 | package eu.omp.irap.vespa.epntapclient.votable.utils; |
18 | 18 | |
19 | -import java.io.FileWriter; | |
20 | -import java.io.IOException; | |
21 | 19 | import java.util.logging.Logger; |
22 | 20 | |
23 | -import com.google.gson.Gson; | |
24 | -import com.google.gson.GsonBuilder; | |
25 | - | |
26 | 21 | /** |
27 | 22 | * @author N. Jourdane |
28 | 23 | */ |
29 | -public class Utils { | |
24 | +public class Strings { | |
30 | 25 | |
31 | 26 | /** The logger for the class Utils. */ |
32 | - private static final Logger logger = Logger.getLogger(Utils.class.getName()); | |
27 | + private static final Logger logger = Logger.getLogger(Strings.class.getName()); | |
33 | 28 | |
34 | 29 | |
35 | 30 | /** Private constructor to hide the implicit public one. */ |
36 | - private Utils() { | |
31 | + private Strings() { | |
37 | 32 | } |
38 | 33 | |
39 | 34 | |
... | ... | @@ -88,27 +83,4 @@ public class Utils { |
88 | 83 | } |
89 | 84 | } |
90 | 85 | |
91 | - | |
92 | - /** | |
93 | - * Print the specified object in JSON format in a file on the temporary directory. | |
94 | - * | |
95 | - * @param title The name of the file. | |
96 | - * @param obj the object to print in a file. | |
97 | - * @return The path of the file. | |
98 | - */ | |
99 | - public static String printObject(String title, Object obj) { | |
100 | - Gson gson = new GsonBuilder().setPrettyPrinting().create(); | |
101 | - String json = gson.toJson(obj); | |
102 | - String path = Const.TMP_DIR + "/" + title + ".json"; | |
103 | - try (FileWriter writer = new FileWriter(path)) { | |
104 | - writer.write(json); | |
105 | - | |
106 | - } catch (IOException e) { | |
107 | - Utils.logger.warning("Can not print in the file " + path + e); | |
108 | - } | |
109 | - Utils.logger.info("A json file representing " + title + " (" + obj.getClass().getName() | |
110 | - + ") has been created on " + path); | |
111 | - | |
112 | - return path; | |
113 | - } | |
114 | 86 | } | ... | ... |