mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-27 14:31:16 +00:00
More documentation.
This commit is contained in:
@@ -26,6 +26,9 @@ import java.io.Serializable;
|
||||
*/
|
||||
public class ByteArrayRange implements Serializable {
|
||||
|
||||
/**
|
||||
* Empty byte array range.
|
||||
*/
|
||||
public static final ByteArrayRange EMPTY = new ByteArrayRange(SWFInputStream.BYTE_ARRAY_EMPTY);
|
||||
|
||||
private final byte[] array;
|
||||
@@ -34,18 +37,32 @@ public class ByteArrayRange implements Serializable {
|
||||
|
||||
private final int length;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param array Byte array
|
||||
*/
|
||||
public ByteArrayRange(byte[] array) {
|
||||
this.array = array;
|
||||
this.pos = 0;
|
||||
this.length = array.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param array Byte array
|
||||
* @param pos Position
|
||||
* @param length Length
|
||||
*/
|
||||
public ByteArrayRange(byte[] array, int pos, int length) {
|
||||
this.array = array;
|
||||
this.pos = pos;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param hexString Hex string
|
||||
*/
|
||||
public ByteArrayRange(String hexString) {
|
||||
byte[] array = new byte[hexString.length() / 2];
|
||||
for (int i = 0; i < hexString.length() / 2; i++) {
|
||||
@@ -56,34 +73,67 @@ public class ByteArrayRange implements Serializable {
|
||||
this.length = array.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array.
|
||||
* @return The byte array
|
||||
*/
|
||||
public byte[] getArray() {
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets position.
|
||||
* @return Position
|
||||
*/
|
||||
public int getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets length.
|
||||
* @return Length
|
||||
*/
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets byte at index.
|
||||
* @param index Index
|
||||
* @return Byte at index
|
||||
*/
|
||||
public byte get(int index) {
|
||||
return array[pos + index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets range data.
|
||||
* @return Range data
|
||||
*/
|
||||
public byte[] getRangeData() {
|
||||
byte[] data = new byte[length];
|
||||
System.arraycopy(array, pos, data, 0, length);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets range data.
|
||||
* @param pos Position
|
||||
* @param length Length
|
||||
* @return Range data
|
||||
*/
|
||||
public byte[] getRangeData(int pos, int length) {
|
||||
byte[] data = new byte[length];
|
||||
System.arraycopy(array, this.pos + pos, data, 0, length);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets sub range.
|
||||
* @param pos Position
|
||||
* @param length Length
|
||||
* @return Sub range
|
||||
*/
|
||||
public ByteArrayRange getSubRange(int pos, int length) {
|
||||
return new ByteArrayRange(array, this.pos + pos, length);
|
||||
}
|
||||
|
||||
@@ -49,8 +49,14 @@ public class Cache<K, V> implements Freed {
|
||||
|
||||
private static final List<WeakReference<Cache>> instances = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Storage type - files
|
||||
*/
|
||||
public static final int STORAGE_FILES = 1;
|
||||
|
||||
/**
|
||||
* Storage type - memory
|
||||
*/
|
||||
public static final int STORAGE_MEMORY = 2;
|
||||
|
||||
private final boolean weak;
|
||||
@@ -83,6 +89,16 @@ public class Cache<K, V> implements Freed {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance.
|
||||
* @param weak Weak
|
||||
* @param memoryOnly Memory only
|
||||
* @param name Name
|
||||
* @param temporary Temporary
|
||||
* @return Cache
|
||||
* @param <K> Key
|
||||
* @param <V> Value
|
||||
*/
|
||||
public static <K, V> Cache<K, V> getInstance(boolean weak, boolean memoryOnly, String name, boolean temporary) {
|
||||
if (oldCleaner == null) {
|
||||
oldCleaner = new Thread("Cache cleaner") {
|
||||
@@ -115,6 +131,9 @@ public class Cache<K, V> implements Freed {
|
||||
|
||||
private static int storageType = STORAGE_FILES;
|
||||
|
||||
/**
|
||||
* Clear all caches.
|
||||
*/
|
||||
public static void clearAll() {
|
||||
synchronized (instancesLock) {
|
||||
for (WeakReference<Cache> cw : instances) {
|
||||
@@ -127,6 +146,10 @@ public class Cache<K, V> implements Freed {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets storage type.
|
||||
* @param storageType Storage type
|
||||
*/
|
||||
public static void setStorageType(int storageType) {
|
||||
if (storageType == Cache.storageType) {
|
||||
return;
|
||||
@@ -144,6 +167,10 @@ public class Cache<K, V> implements Freed {
|
||||
Cache.storageType = storageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage type.
|
||||
* @return Storage type
|
||||
*/
|
||||
public static int getStorageType() {
|
||||
return storageType;
|
||||
}
|
||||
@@ -183,6 +210,11 @@ public class Cache<K, V> implements Freed {
|
||||
initCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains.
|
||||
* @param key Key
|
||||
* @return Contains
|
||||
*/
|
||||
public synchronized boolean contains(K key) {
|
||||
boolean ret = cache.containsKey(key);
|
||||
if (ret) {
|
||||
@@ -191,11 +223,18 @@ public class Cache<K, V> implements Freed {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears cache.
|
||||
*/
|
||||
public synchronized void clear() {
|
||||
cache.clear();
|
||||
lastAccessed.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes key.
|
||||
* @param key Key
|
||||
*/
|
||||
public synchronized void remove(K key) {
|
||||
if (cache.containsKey(key)) {
|
||||
cache.remove(key);
|
||||
@@ -205,11 +244,21 @@ public class Cache<K, V> implements Freed {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets item by key.
|
||||
* @param key Key
|
||||
* @return Item
|
||||
*/
|
||||
public synchronized V get(K key) {
|
||||
lastAccessed.put(key, System.currentTimeMillis());
|
||||
return cache.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts key and value.
|
||||
* @param key Key
|
||||
* @param value Value
|
||||
*/
|
||||
public synchronized void put(K key, V value) {
|
||||
cache.put(key, value);
|
||||
lastAccessed.put(key, System.currentTimeMillis());
|
||||
@@ -227,6 +276,10 @@ public class Cache<K, V> implements Freed {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets keys.
|
||||
* @return Keys
|
||||
*/
|
||||
public Set<K> keys() {
|
||||
Set<K> ret = new HashSet<>();
|
||||
ret.addAll(cache.keySet());
|
||||
|
||||
@@ -24,5 +24,16 @@ package com.jpexs.helpers;
|
||||
*/
|
||||
public abstract class Callback<T> {
|
||||
|
||||
/**
|
||||
* Calls
|
||||
* @param arg1 Argument
|
||||
*/
|
||||
public abstract void call(T arg1);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Callback() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,9 @@ public abstract class CancellableWorker<T> implements RunnableFuture<T> {
|
||||
|
||||
private Thread thread;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public CancellableWorker() {
|
||||
super();
|
||||
Callable<T> callable = new Callable<T>() {
|
||||
@@ -71,6 +74,11 @@ public abstract class CancellableWorker<T> implements RunnableFuture<T> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Do in background.
|
||||
* @return Result
|
||||
* @throws Exception On error
|
||||
*/
|
||||
protected abstract T doInBackground() throws Exception;
|
||||
|
||||
@Override
|
||||
@@ -79,12 +87,21 @@ public abstract class CancellableWorker<T> implements RunnableFuture<T> {
|
||||
future.run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before starting the worker.
|
||||
*/
|
||||
protected void onStart() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after the worker is done.
|
||||
*/
|
||||
protected void done() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the worker.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final void execute() {
|
||||
Thread t = Thread.currentThread();
|
||||
@@ -108,6 +125,9 @@ public abstract class CancellableWorker<T> implements RunnableFuture<T> {
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the worker is cancelled.
|
||||
*/
|
||||
public void workerCancelled() {
|
||||
|
||||
}
|
||||
@@ -141,6 +161,17 @@ public abstract class CancellableWorker<T> implements RunnableFuture<T> {
|
||||
done();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a callable with a timeout.
|
||||
* @param c Callable
|
||||
* @param timeout Timeout
|
||||
* @param timeUnit Time unit
|
||||
* @return Result
|
||||
* @param <T> Result type
|
||||
* @throws InterruptedException On interrupt
|
||||
* @throws ExecutionException On execution error
|
||||
* @throws TimeoutException On timeout
|
||||
*/
|
||||
public static <T> T call(final Callable<T> c, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
Thread t = Thread.currentThread();
|
||||
if (t.isInterrupted()) {
|
||||
@@ -161,6 +192,9 @@ public abstract class CancellableWorker<T> implements RunnableFuture<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels all background threads.
|
||||
*/
|
||||
public static void cancelBackgroundThreads() {
|
||||
List<CancellableWorker> oldWorkers = workers;
|
||||
workers = Collections.synchronizedList(new ArrayList<CancellableWorker>());
|
||||
@@ -173,6 +207,9 @@ public abstract class CancellableWorker<T> implements RunnableFuture<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the worker.
|
||||
*/
|
||||
public void free() {
|
||||
future = null;
|
||||
for (CancellableWorker w : subWorkers) {
|
||||
|
||||
@@ -30,5 +30,9 @@ import java.lang.annotation.Target;
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface ConcreteClasses {
|
||||
|
||||
/**
|
||||
* Concrete classes.
|
||||
* @return Concrete classes
|
||||
*/
|
||||
Class<?>[] value();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ClassFileManager extends
|
||||
/**
|
||||
* Will initialize the manager with the specified standard java file manager
|
||||
*
|
||||
* @param standardManager
|
||||
* @param standardManager The standard file manager
|
||||
*/
|
||||
public ClassFileManager(StandardJavaFileManager standardManager) {
|
||||
super(standardManager);
|
||||
@@ -54,8 +54,8 @@ public class ClassFileManager extends
|
||||
* byte code created by the compiler and stored in the JavaClassObject, and
|
||||
* returns the Class for it
|
||||
*
|
||||
* @param location
|
||||
* @return
|
||||
* @param location Location
|
||||
* @return Class loader
|
||||
*/
|
||||
@Override
|
||||
public ClassLoader getClassLoader(Location location) {
|
||||
@@ -74,12 +74,12 @@ public class ClassFileManager extends
|
||||
* Gives the compiler an instance of the JavaClassObject so that the
|
||||
* compiler can write the byte code into it.
|
||||
*
|
||||
* @param location
|
||||
* @param className
|
||||
* @param kind
|
||||
* @param sibling
|
||||
* @return
|
||||
* @throws java.io.IOException
|
||||
* @param location Location
|
||||
* @param className Class name
|
||||
* @param kind Kind
|
||||
* @param sibling Sibling
|
||||
* @return Java file object
|
||||
* @throws IOException On I/O error
|
||||
*/
|
||||
@Override
|
||||
public JavaFileObject getJavaFileForOutput(Location location,
|
||||
|
||||
Reference in New Issue
Block a user