Skip to content

Commit 8cfaace

Browse files
committed
refactor: minor code clean up
1 parent f2d3cee commit 8cfaace

15 files changed

Lines changed: 41 additions & 36 deletions

src/main/java/net/trustyuri/FixTrustyFile.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ public static void fix(File file) throws IOException, TrustyUriException {
4141
* Creates a new FixTrustyFile object for the given trusty file.
4242
*
4343
* @param file the trusty file to fix
44-
* @throws IOException if there is an error reading the file
4544
*/
46-
public FixTrustyFile(File file) throws IOException {
45+
public FixTrustyFile(File file) {
4746
this.file = file;
4847
}
4948

src/main/java/net/trustyuri/RunBatch.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ private RunBatch() {
2626
* Runs a batch of commands from a file, one per line. Lines starting with # are ignored.
2727
*
2828
* @param args the first argument is the batch file to run
29-
* @throws IOException if there is an error reading the batch file or the running file
30-
* @throws RDF4JException if there is an error running a command that uses RDF4J
31-
* @throws TrustyUriException if there is an error running a command that uses TrustyUri
29+
* @throws IOException if there is an error reading the batch file or the running file
30+
* @throws RDF4JException if there is an error running a command that uses RDF4J
3231
*/
33-
public static void main(String[] args) throws IOException, RDF4JException, TrustyUriException {
32+
public static void main(String[] args) throws IOException, RDF4JException {
3433
String batchFile = args[0];
3534

3635
BufferedReader reader = new BufferedReader(new FileReader(batchFile));

src/main/java/net/trustyuri/TrustyUriModule.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ public interface TrustyUriModule {
1919
*
2020
* @return the module ID
2121
*/
22-
public String getModuleId();
22+
String getModuleId();
2323

2424
/**
2525
* Returns the algorithm ID used for the transformation to ni-URIs.
2626
*
2727
* @return the algorithm ID
2828
*/
29-
public String getAlgorithmId();
29+
String getAlgorithmId();
3030

3131
/**
3232
* Returns the length of the trusty URI data part in bytes.
3333
*
3434
* @return data part length
3535
*/
36-
public int getDataPartLength();
36+
int getDataPartLength();
3737

3838
/**
3939
* Checks the hash for the given resource.
@@ -43,7 +43,7 @@ public interface TrustyUriModule {
4343
* @throws IOException if an I/O error occurs
4444
* @throws TrustyUriException if the trusty URI is invalid
4545
*/
46-
public boolean hasCorrectHash(TrustyUriResource resource) throws IOException, TrustyUriException;
46+
boolean hasCorrectHash(TrustyUriResource resource) throws IOException, TrustyUriException;
4747

4848
/**
4949
* Fixes the trusty URI of the given file by calculating the correct hash and renaming the file
@@ -53,14 +53,14 @@ public interface TrustyUriModule {
5353
* @throws TrustyUriException if the trusty URI is invalid
5454
* @throws UnsupportedOperationException if the module does not support fixing trusty URIs
5555
*/
56-
public void fixTrustyFile(File file) throws IOException, TrustyUriException, UnsupportedOperationException;
56+
void fixTrustyFile(File file) throws IOException, TrustyUriException, UnsupportedOperationException;
5757

5858
/**
5959
* Checks whether the given URI could be a trusty URI represented by this module.
6060
*
6161
* @param uri the URI
6262
* @return true if the URI matches the format of this module
6363
*/
64-
public boolean matches(IRI uri);
64+
boolean matches(IRI uri);
6565

6666
}

src/main/java/net/trustyuri/TrustyUriResource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.net.URL;
88
import java.net.URLConnection;
99
import java.nio.charset.Charset;
10+
import java.nio.charset.StandardCharsets;
1011
import java.util.Optional;
1112
import java.util.zip.GZIPInputStream;
1213

@@ -166,7 +167,7 @@ public InputStream getInputStream() {
166167
* @return an InputStreamReader for the resource, using UTF-8 encoding
167168
*/
168169
public InputStreamReader getInputStreamReader() {
169-
return new InputStreamReader(in, Charset.forName("UTF-8"));
170+
return new InputStreamReader(in, StandardCharsets.UTF_8);
170171
}
171172

172173
/**

src/main/java/net/trustyuri/TrustyUriUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ public static String getBase64Hash(String s) {
153153
*/
154154
public static byte[] getBase64Bytes(String base64String) {
155155
base64String = base64String.replace('-', '+').replace('_', '/');
156-
while (base64String.length() % 4 > 0) base64String = base64String + "=";
156+
while (base64String.length() % 4 > 0) {
157+
base64String = base64String + "=";
158+
}
157159
return DatatypeConverter.parseBase64Binary(base64String);
158160
}
159161

src/main/java/net/trustyuri/file/ProcessFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static void process(File file) throws IOException {
4141
base = filename.replaceFirst("^(.*)(\\.[A-Za-z0-9\\-_]{0,20})$", "$1");
4242
}
4343
String glue = "";
44-
if (base.length() > 0 && base.charAt(base.length() - 1) != '.') {
44+
if (!base.isEmpty() && base.charAt(base.length() - 1) != '.') {
4545
glue = ".";
4646
}
4747
File hashFile = new File(file.getParentFile(), base + glue + ac.toString() + ext);

src/main/java/net/trustyuri/rdf/CheckLargeRdf.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.io.*;
1717
import java.nio.charset.Charset;
18+
import java.nio.charset.StandardCharsets;
1819
import java.security.MessageDigest;
1920
import java.util.Comparator;
2021
import java.util.List;
@@ -80,7 +81,7 @@ public boolean check() throws IOException, TrustyUriException {
8081
public void handleStatement(Statement st) throws RDFHandlerException {
8182
String s = SerStatementComparator.toString(st) + "\n";
8283
try {
83-
preOut.write(s.getBytes(Charset.forName("UTF-8")));
84+
preOut.write(s.getBytes(StandardCharsets.UTF_8));
8485
} catch (IOException ex) {
8586
ex.printStackTrace();
8687
}

src/main/java/net/trustyuri/rdf/RdfFileContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void handleStatement(Statement st) throws RDFHandlerException {
6767
obj = st.getObject();
6868
rdfEntityMap.put(obj, obj);
6969
}
70-
Resource context = null;
70+
Resource context;
7171
if (st.getContext() == null) {
7272
st = SimpleValueFactory.getInstance().createStatement(subj, pred, obj);
7373
} else {

src/main/java/net/trustyuri/rdf/RdfHasher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static String getDigestString(List<Statement> statements) {
136136
* @return the message digest
137137
*/
138138
public static MessageDigest getDigest() {
139-
MessageDigest md = null;
139+
MessageDigest md;
140140
try {
141141
md = MessageDigest.getInstance("SHA-256");
142142
} catch (NoSuchAlgorithmException ex) {

src/main/java/net/trustyuri/rdf/RdfUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.io.*;
1414
import java.net.URI;
1515
import java.net.URISyntaxException;
16-
import java.nio.charset.Charset;
16+
import java.nio.charset.StandardCharsets;
1717
import java.util.HashSet;
1818
import java.util.Map;
1919
import java.util.zip.GZIPOutputStream;
@@ -232,7 +232,7 @@ public static RdfFileContent load(InputStream in, RDFFormat format) throws IOExc
232232
RdfFileContent content = new RdfFileContent(format);
233233
p.setRDFHandler(content);
234234
try {
235-
p.parse(new InputStreamReader(in, Charset.forName("UTF-8")), "");
235+
p.parse(new InputStreamReader(in, StandardCharsets.UTF_8), "");
236236
} catch (RDF4JException ex) {
237237
ex.printStackTrace();
238238
throw new TrustyUriException(ex);
@@ -283,11 +283,11 @@ public static void fixTrustyRdf(File file) throws IOException, TrustyUriExceptio
283283
OutputStream out;
284284
String filename = r.getFilename().replace(oldArtifactCode.toString(), newArtifactCode.toString());
285285
if (filename.matches(".*\\.(gz|gzip)")) {
286-
out = new GZIPOutputStream(new FileOutputStream(new File("fixed." + filename)));
286+
out = new GZIPOutputStream(new FileOutputStream("fixed." + filename));
287287
} else {
288-
out = new FileOutputStream(new File("fixed." + filename));
288+
out = new FileOutputStream("fixed." + filename);
289289
}
290-
RDFWriter writer = Rio.createWriter(r.getFormat(RDFFormat.TRIG), new OutputStreamWriter(out, Charset.forName("UTF-8")));
290+
RDFWriter writer = Rio.createWriter(r.getFormat(RDFFormat.TRIG), new OutputStreamWriter(out, StandardCharsets.UTF_8));
291291
TransformRdf.transformPreprocessed(content, null, writer, null);
292292
}
293293

0 commit comments

Comments
 (0)