/** {@inheritDoc} */ @Override public Response handleRequest(REQ request, Response response) throws IOException { String path = request.getUri().getPath(); int lastSlash = path.lastIndexOf('/'); String filename = path.substring(lastSlash + 1); InputStream fileInputStream = getClass().getResourceAsStream(resourcePathPrefix + filename); if (fileInputStream == null) { return response.setStatusCode(404).setStatusText("Not found."); } StreamCopier.copy(fileInputStream, response.getContent()); return response.setStatusCode(200).setStatusText("OK").setContentType(mimeType); }
/** * "\0REQ" == [ 00 52 45 51 ] == 5391697 * * <p>"\0RES" == [ 00 52 45 53 ] == 5391699 * * @param bytes array of bytes containing magic code for a packet * @throws BadMagicException if byte array is not 4 bytes long */ public static GearmanPacketMagic fromBytes(byte[] bytes) { if (bytes != null && bytes.length == 4) { int magic = ByteUtils.fromBigEndian(bytes); if (magic == ByteUtils.fromBigEndian(REQ.toBytes())) { return REQ; } if (magic == ByteUtils.fromBigEndian(RES.toBytes())) { return RES; } } throw new BadMagicException(ByteUtils.toHex(bytes)); }