mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-10-01 18:07:49 +00:00
init, thx MrExtremez
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package org.apollo.jagcached.net.jaggrab;
|
||||
|
||||
/**
|
||||
* Represents the request for a single file using the JAGGRAB protocol.
|
||||
* @author Graham
|
||||
*/
|
||||
public final class JagGrabRequest {
|
||||
|
||||
/**
|
||||
* The path to the file.
|
||||
*/
|
||||
private final String filePath;
|
||||
|
||||
/**
|
||||
* Creates the request.
|
||||
* @param filePath The file path.
|
||||
*/
|
||||
public JagGrabRequest(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file path.
|
||||
* @return The file path.
|
||||
*/
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.apollo.jagcached.net.jaggrab;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
|
||||
|
||||
/**
|
||||
* A {@link OneToOneDecoder} for the JAGGRAB protocol.
|
||||
* @author Graham
|
||||
*/
|
||||
public final class JagGrabRequestDecoder extends OneToOneDecoder {
|
||||
|
||||
@Override
|
||||
protected Object decode(ChannelHandlerContext ctx, Channel c, Object msg) throws Exception {
|
||||
if (msg instanceof String) {
|
||||
String str = ((String) msg);
|
||||
if (str.startsWith("JAGGRAB /")) {
|
||||
String filePath = str.substring(8).trim();
|
||||
return new JagGrabRequest(filePath);
|
||||
} else {
|
||||
throw new Exception("corrupted request line");
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.apollo.jagcached.net.jaggrab;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
|
||||
/**
|
||||
* Represents a single JAGGRAB reponse.
|
||||
* @author Graham
|
||||
*/
|
||||
public final class JagGrabResponse {
|
||||
|
||||
/**
|
||||
* The file data.
|
||||
*/
|
||||
private final ChannelBuffer fileData;
|
||||
|
||||
/**
|
||||
* Creates the response.
|
||||
* @param fileData The file data.
|
||||
*/
|
||||
public JagGrabResponse(ChannelBuffer fileData) {
|
||||
this.fileData = fileData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file data.
|
||||
* @return The file data.
|
||||
*/
|
||||
public ChannelBuffer getFileData() {
|
||||
return fileData;
|
||||
}
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package org.apollo.jagcached.net.jaggrab;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||
|
||||
/**
|
||||
* A {@link OneToOneEncoder} for the JAGGRAB protocol.
|
||||
* @author Graham
|
||||
*/
|
||||
public final class JagGrabResponseEncoder extends OneToOneEncoder {
|
||||
|
||||
@Override
|
||||
protected Object encode(ChannelHandlerContext ctx, Channel c, Object msg) throws Exception {
|
||||
if (msg instanceof JagGrabResponse) {
|
||||
JagGrabResponse resp = (JagGrabResponse) msg;
|
||||
return resp.getFileData();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user