Siema mam pewien problem z kodem (nie moim), jest on odczytany z pliku jar. Lecz kiedy wklejam go do kompilatora nie chce się skompilować.
Prosił bym o pomoc.
oto kod:
Ps. Gdyby były potrzebne inne klasy, to mogę podać.
Prosił bym o pomoc.
oto kod:
Kod:
import java.io.*;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;
public class Util {
public static byte[] getBytesFromFile(File file) throws IOException {
/* 22*/ InputStream is = new FileInputStream(file);
/* 25*/ long length = file.length();
/* 27*/ if (length <= 0x7fffffffL);
/* 32*/ byte bytes[] = new byte[(int)length];
/* 35*/ int offset = 0;
/* 36*/ for (int numRead = 0; offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0; offset += numRead) { }
/* 43*/ if (offset < bytes.length) {
/* 44*/ throw new IOException((new StringBuilder()).append("Could not completely read file ").append(file.getName()).toString());
} else {
/* 48*/ is.close();
/* 49*/ return bytes;
}
}
public static byte[] getBytes(InputStream is) throws IOException {
/* 55*/ int size = 1024;
byte buf[];
/* 58*/ if (is instanceof ByteArrayInputStream) {
/* 59*/ size = is.available();
/* 60*/ buf = new byte[size];
/* 61*/ int len = is.read(buf, 0, size);
} else {
/* 63*/ ByteArrayOutputStream bos = new ByteArrayOutputStream();
/* 64*/ buf = new byte[size];
int len;
/* 65*/ while ((len = is.read(buf, 0, size)) != -1) {
/* 66*/ bos.write(buf, 0, len);
}
/* 67*/ buf = bos.toByteArray();
}
/* 69*/ return buf;
}
public static String calculateHash(String digest_type, String fileName) {
FileInputStream fis;
/* 74*/ File file = new File(fileName);
/* 75*/ if (!file.exists() || !file.isFile()) {
/* 76*/ return "FILE_DOESNT_EXIST";
}
/* 78*/ fis = null;
String s;
/* 81*/ fis = new FileInputStream(fileName);
/* 82*/ s = calculateHash(digest_type, ((InputStream) (fis)));
/* 92*/ try {
/* 92*/ if (fis != null) {
/* 93*/ fis.close();
}
}
/* 95*/ catch (IOException e) {
/* 98*/ e.printStackTrace();
}
/* 99*/ return s;
Exception e;
/* 84*/ e;
/* 86*/ String s1 = "ERROR CALCLATING";
/* 92*/ try {
/* 92*/ if (fis != null) {
/* 93*/ fis.close();
}
}
/* 95*/ catch (IOException e) {
/* 98*/ e.printStackTrace();
}
/* 99*/ return s1;
Exception exception;
/* 90*/ exception;
/* 92*/ try {
/* 92*/ if (fis != null) {
/* 93*/ fis.close();
}
}
/* 95*/ catch (IOException e) {
/* 98*/ e.printStackTrace();
}
/* 99*/ throw exception;
}
public static String calculateHash(String digest_type, InputStream input) {
byte hash[];
/* 107*/ MessageDigest algorithm = MessageDigest.getInstance(digest_type);
/* 108*/ BufferedInputStream bis = new BufferedInputStream(input);
/* 109*/ for (DigestInputStream dis = new DigestInputStream(bis, algorithm); dis.read() != -1;) { }
/* 116*/ hash = algorithm.digest();
/* 118*/ return byteArray2Hex(hash);
NoSuchAlgorithmException e;
/* 120*/ e;
/* 122*/ return "Invalid Hash Algo";
/* 124*/ e;
/* 126*/ return "ERROR CALCLATING";
}
public static String byteArray2Hex(byte hash[]) {
/* 132*/ Formatter formatter = new Formatter();
/* 133*/ byte arr$[] = hash;
/* 133*/ int len$ = arr$.length;
/* 133*/ for (int i$ = 0; i$ < len$; i$++) {
/* 133*/ byte b = arr$[i$];
/* 135*/ formatter.format("%02x", new Object[] {
/* 135*/ Byte.valueOf(b)
});
}
/* 137*/ return formatter.toString().toLowerCase();
}
public static String sanitize(File dir, String entry) {
/* 149*/ if (entry.length() == 0) {
/* 151*/ return null;
}
/* 154*/ if ((new File(entry)).isAbsolute()) {
/* 156*/ return null;
}
String DirPath;
String EntryPath;
/* 161*/ DirPath = (new StringBuilder()).append(dir.getPath()).append(File.separator).toString();
/* 162*/ EntryPath = (new File(dir, entry)).getPath();
/* 164*/ if (!EntryPath.startsWith(DirPath)) {
/* 166*/ return null;
}
/* 169*/ return EntryPath.substring(DirPath.length());
Exception e;
/* 171*/ e;
/* 176*/ return null;
}
public static boolean downloadUrlToFile(String url, String filename) {
/* 189*/ url = url.replace("\\", "/");
/* 191*/ ReadableByteChannel rbc = Channels.newChannel((new URL(url)).openStream());
/* 194*/ File file = (new File(filename)).getParentFile();
/* 195*/ if (file != null) {
/* 196*/ file.mkdirs();
}
/* 198*/ FileOutputStream fos = new FileOutputStream(filename);
/* 199*/ fos.getChannel().transferFrom(rbc, 0L, 0x1000000L);
/* 200*/ fos.close();
/* 201*/ return true;
Exception e;
/* 203*/ e;
/* 205*/ e.printStackTrace();
/* 206*/ return false;
}
}