Archiviert
13
0

Makes more sense to put this in the reflect lookup.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-04-28 17:27:58 +02:00
Ursprung bec05967d3
Commit 8964246e22
2 geänderte Dateien mit 277 neuen und 282 gelöschten Zeilen

Datei anzeigen

@ -1,22 +1,14 @@
package com.comphenix.protocol.injector.server; package com.comphenix.protocol.injector.server;
import java.io.FilterInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress; import java.net.SocketAddress;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection;
public abstract class AbstractInputStreamLookup { public abstract class AbstractInputStreamLookup {
// Used to access the inner input stream of a filtered input stream
private static Field filteredInputField;
// Error reporter // Error reporter
protected final ErrorReporter reporter; protected final ErrorReporter reporter;
@ -28,30 +20,6 @@ public abstract class AbstractInputStreamLookup {
this.server = server; this.server = server;
} }
/**
* Retrieve the underlying input stream that is associated with a given filter input stream.
* @param filtered - the filter input stream.
* @return The underlying input stream that is being filtered.
* @throws FieldAccessException Unable to access input stream.
*/
protected static InputStream getInputStream(FilterInputStream filtered) {
if (filteredInputField == null)
filteredInputField = FuzzyReflection.fromClass(FilterInputStream.class, true).
getFieldByType("in", InputStream.class);
InputStream current = filtered;
try {
// Iterate until we find the real input stream
while (current instanceof FilterInputStream) {
current = (InputStream) FieldUtils.readField(filteredInputField, current, true);
}
return current;
} catch (IllegalAccessException e) {
throw new FieldAccessException("Cannot access filtered input field.", e);
}
}
/** /**
* Inject the given server thread or dedicated connection. * Inject the given server thread or dedicated connection.
* @param container - class that contains a ServerSocket field. * @param container - class that contains a ServerSocket field.

Datei anzeigen

@ -18,6 +18,9 @@ import com.comphenix.protocol.reflect.FuzzyReflection;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
class InputStreamReflectLookup extends AbstractInputStreamLookup { class InputStreamReflectLookup extends AbstractInputStreamLookup {
// Used to access the inner input stream of a filtered input stream
private static Field filteredInputField;
// The default lookup timeout // The default lookup timeout
private static final long DEFAULT_TIMEOUT = 2000; // ms private static final long DEFAULT_TIMEOUT = 2000; // ms
@ -123,6 +126,30 @@ class InputStreamReflectLookup extends AbstractInputStreamLookup {
return result; return result;
} }
/**
* Retrieve the underlying input stream that is associated with a given filter input stream.
* @param filtered - the filter input stream.
* @return The underlying input stream that is being filtered.
* @throws FieldAccessException Unable to access input stream.
*/
protected static InputStream getInputStream(FilterInputStream filtered) {
if (filteredInputField == null)
filteredInputField = FuzzyReflection.fromClass(FilterInputStream.class, true).
getFieldByType("in", InputStream.class);
InputStream current = filtered;
try {
// Iterate until we find the real input stream
while (current instanceof FilterInputStream) {
current = (InputStream) FieldUtils.readField(filteredInputField, current, true);
}
return current;
} catch (IllegalAccessException e) {
throw new FieldAccessException("Cannot access filtered input field.", e);
}
}
@Override @Override
public void setSocketInjector(SocketAddress address, SocketInjector injector) { public void setSocketInjector(SocketAddress address, SocketInjector injector) {
if (address == null) if (address == null)