Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
fix a bug for initialization in jar state
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottCTD committed Oct 13, 2020
1 parent fcac542 commit 9bcb134
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
35 changes: 5 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>xyz.socttc</groupId>
<artifactId>VocabularyDecoder</artifactId>
<version>0.0.5</version>
<version>0.0.7</version>
<dependencies>

<dependency>
Expand All @@ -15,20 +15,6 @@
<version>20200518</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-assembly-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
</dependency>


</dependencies>

Expand Down Expand Up @@ -69,6 +55,7 @@
<mainClass>xyz.scottc.vd.Main</mainClass>
</manifest>
</archive>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
Expand All @@ -77,26 +64,14 @@
<goals>
<goal>single</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>

</build>

</project>
5 changes: 3 additions & 2 deletions src/main/java/xyz/scottc/vd/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Enumeration;
Expand Down Expand Up @@ -85,7 +86,7 @@ private static void initDirectory() {

private static void initInternalLibraryInJar() throws IOException {
String sourceDir = "internalLibrary/";
String jarPath = FileUtils.getJarFilePath(Main.class);
String jarPath = URLDecoder.decode(FileUtils.getJarFilePath(Main.class), "UTF-8");
JarFile jarFile = new JarFile(jarPath);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
Expand All @@ -95,7 +96,7 @@ private static void initInternalLibraryInJar() throws IOException {
InputStream inputStream = Main.class.getResourceAsStream("/" + filePath);
String fileName = filePath.substring(sourceDir.length());
File targetFile = new File(internalLibrary.getAbsolutePath() + "/" + fileName);
if (!targetFile.isDirectory()) {
if (fileName.contains(".")) {
//ignore whether the file exists, add it to the list if it is a regular file
if (!targetFile.exists()) {
Files.copy(inputStream, targetFile.toPath());
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/xyz/scottc/vd/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.swing.*;
import java.io.*;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class FileUtils {
Expand Down Expand Up @@ -32,6 +33,7 @@ public static byte[] readFromInputStream(InputStream inputStream) throws IOExcep

public static String getJarFilePath(Class<?> object) {
if (object != null) {

return object.getProtectionDomain().getCodeSource().getLocation().getPath();
}
return null;
Expand Down Expand Up @@ -92,6 +94,22 @@ public static void copyFile(InputStream inputStream, File targetDir, String file
}
}

public static void copyTextFile(InputStream inputStream, File target) {
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(target)
));
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
writer.write(new String(buffer, 0, length, StandardCharsets.UTF_8));
}
writer.flush();
} catch (IOException exception) {
exception.printStackTrace();
}
}

public static void closeStream(InputStream inputStream, OutputStream outputStream) {
if (inputStream != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"utter",
"outrage",
"betray",
"affilate",
"affiliate",
"batter",
"irritate",
"oversee",
Expand Down Expand Up @@ -187,7 +187,7 @@
"brutal",
"precedent",
"memoir",
"comtempt",
"contempt",
"mighty",
"glorious",
"heir",
Expand Down

0 comments on commit 9bcb134

Please sign in to comment.