[BUG] Fix files being detected as text when it's a binary
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -42,3 +42,4 @@ bin/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
|
testdir/
|
@@ -44,7 +44,6 @@ dependencies {
|
|||||||
shadeMe 'org.ow2.asm:asm-commons:9.3'
|
shadeMe 'org.ow2.asm:asm-commons:9.3'
|
||||||
shadeMe "fr.stevecohen.jarmanager:JarManager:0.5.0"
|
shadeMe "fr.stevecohen.jarmanager:JarManager:0.5.0"
|
||||||
shadeMe 'org.apache.commons:commons-compress:1.24.0'
|
shadeMe 'org.apache.commons:commons-compress:1.24.0'
|
||||||
shadeMe 'org.apache.tika:tika-core:1.28'
|
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.30'
|
compileOnly 'org.projectlombok:lombok:1.18.30'
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.30'
|
annotationProcessor 'org.projectlombok:lombok:1.18.30'
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
version_base=1.0
|
version_base=1.0
|
||||||
version_patch=2
|
version_patch=3
|
@@ -418,7 +418,7 @@ public class JarMergeAction {
|
|||||||
for (Map.Entry<String, String> entry : relocations.entrySet()) {
|
for (Map.Entry<String, String> entry : relocations.entrySet()) {
|
||||||
line = line.replace(entry.getKey(), entry.getValue());
|
line = line.replace(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
sb.append(line).append("\n");
|
sb.append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner.close();
|
scanner.close();
|
||||||
|
@@ -9,9 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.hypherionmc.modfusioner.utils;
|
package com.hypherionmc.modfusioner.utils;
|
||||||
|
|
||||||
import org.apache.tika.Tika;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -27,10 +25,22 @@ public class FileChecks {
|
|||||||
* @param file - The file to test
|
* @param file - The file to test
|
||||||
* @return - True if binary
|
* @return - True if binary
|
||||||
*/
|
*/
|
||||||
public static boolean isBinary(@NotNull File file) throws IOException {
|
public static boolean isBinary(@NotNull File file) {
|
||||||
Tika tika = new Tika();
|
try (FileInputStream inputStream = new FileInputStream(file)) {
|
||||||
String detectedType = tika.detect(file);
|
int size = (int) Math.min(file.length(), 4096);
|
||||||
return detectedType.equals("application/octet-stream");
|
byte[] data = new byte[size];
|
||||||
|
int bytesRead = inputStream.read(data, 0, size);
|
||||||
|
|
||||||
|
for (int i = 0; i < bytesRead; i++) {
|
||||||
|
if (data[i] == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user