[BUG] Fix files being detected as text when it's a binary
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -41,4 +41,5 @@ bin/
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
|
||||
.idea
|
||||
.idea
|
||||
testdir/
|
@@ -44,7 +44,6 @@ dependencies {
|
||||
shadeMe 'org.ow2.asm:asm-commons:9.3'
|
||||
shadeMe "fr.stevecohen.jarmanager:JarManager:0.5.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'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.30'
|
||||
|
@@ -1,2 +1,2 @@
|
||||
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()) {
|
||||
line = line.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
sb.append(line).append("\n");
|
||||
sb.append(line);
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
|
@@ -9,9 +9,7 @@
|
||||
*/
|
||||
package com.hypherionmc.modfusioner.utils;
|
||||
|
||||
import org.apache.tika.Tika;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -27,10 +25,22 @@ public class FileChecks {
|
||||
* @param file - The file to test
|
||||
* @return - True if binary
|
||||
*/
|
||||
public static boolean isBinary(@NotNull File file) throws IOException {
|
||||
Tika tika = new Tika();
|
||||
String detectedType = tika.detect(file);
|
||||
return detectedType.equals("application/octet-stream");
|
||||
public static boolean isBinary(@NotNull File file) {
|
||||
try (FileInputStream inputStream = new FileInputStream(file)) {
|
||||
int size = (int) Math.min(file.length(), 4096);
|
||||
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