init, thx MrExtremez

This commit is contained in:
Nicola Paolucci
2019-06-18 15:04:35 -04:00
commit ea51313125
2488 changed files with 150207 additions and 0 deletions
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}