/** * pack header by FastDFS transfer protocol * * @param cmd which command to send * @param pkg_len package body length * @param errno status code, should be (byte)0 * @return packed byte buffer */ public static byte[] packHeader(byte cmd, long pkg_len, byte errno) throws UnsupportedEncodingException { byte[] header; byte[] hex_len; header = new byte[FDFS_PROTO_PKG_LEN_SIZE + 2]; Arrays.fill(header, (byte) 0); hex_len = ProtoCommon.long2buff(pkg_len); System.arraycopy(hex_len, 0, header, 0, hex_len.length); header[PROTO_HEADER_CMD_INDEX] = cmd; header[PROTO_HEADER_STATUS_INDEX] = errno; return header; }
offset = header.length; hexLenBytes = ProtoCommon.long2buff(appender_filename.length()); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length; hexLenBytes = ProtoCommon.long2buff(file_offset); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length; hexLenBytes = ProtoCommon.long2buff(modify_size); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length;
offset = header.length; hexLenBytes = ProtoCommon.long2buff(appender_filename.length()); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length; hexLenBytes = ProtoCommon.long2buff(file_size); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length;
+ masterFilenameBytes.length + file_size; hexLenBytes = ProtoCommon.long2buff(master_filename.length()); System.arraycopy(hexLenBytes, 0, sizeBytes, 0, hexLenBytes.length); offset = hexLenBytes.length; hexLenBytes = ProtoCommon.long2buff(file_size); System.arraycopy(hexLenBytes, 0, sizeBytes, offset, hexLenBytes.length);
offset = header.length; hexLenBytes = ProtoCommon.long2buff(appender_filename.length()); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length; hexLenBytes = ProtoCommon.long2buff(truncated_file_size); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length;
/** * pack header by FastDFS transfer protocol * @param cmd which command to send * @param pkg_len package body length * @param errno status code, should be (byte)0 * @return packed byte buffer */ public static byte[] packHeader(byte cmd, long pkg_len, byte errno) throws UnsupportedEncodingException { byte[] header; byte[] hex_len; header = new byte[FDFS_PROTO_PKG_LEN_SIZE + 2]; Arrays.fill(header, (byte) 0); hex_len = ProtoCommon.long2buff(pkg_len); System.arraycopy(hex_len, 0, header, 0, hex_len.length); header[PROTO_HEADER_CMD_INDEX] = cmd; header[PROTO_HEADER_STATUS_INDEX] = errno; return header; }
/** * pack header by FastDFS transfer protocol * * @param cmd which command to send * @param pkg_len package body length * @param errno status code, should be (byte)0 * @return packed byte buffer */ public static byte[] packHeader(byte cmd, long pkg_len, byte errno) throws UnsupportedEncodingException { byte[] header; byte[] hex_len; header = new byte[FDFS_PROTO_PKG_LEN_SIZE + 2]; Arrays.fill(header, (byte) 0); hex_len = ProtoCommon.long2buff(pkg_len); System.arraycopy(hex_len, 0, header, 0, hex_len.length); header[PROTO_HEADER_CMD_INDEX] = cmd; header[PROTO_HEADER_STATUS_INDEX] = errno; return header; }
/** * pack header by FastDFS transfer protocol * @param cmd which command to send * @param pkg_len package body length * @param errno status code, should be (byte)0 * @return packed byte buffer */ public static byte[] packHeader(byte cmd, long pkg_len, byte errno) throws UnsupportedEncodingException { byte[] header; byte[] hex_len; header = new byte[FDFS_PROTO_PKG_LEN_SIZE + 2]; Arrays.fill(header, (byte)0); hex_len = ProtoCommon.long2buff(pkg_len); System.arraycopy(hex_len, 0, header, 0, hex_len.length); header[PROTO_HEADER_CMD_INDEX] = cmd; header[PROTO_HEADER_STATUS_INDEX] = errno; return header; }
/** * pack header by FastDFS transfer protocol * * @param cmd which command to send * @param pkg_len package body length * @param errno status code, should be (byte)0 * @return packed byte buffer */ public static byte[] packHeader(byte cmd, long pkg_len, byte errno) throws UnsupportedEncodingException { byte[] header; byte[] hex_len; header = new byte[FDFS_PROTO_PKG_LEN_SIZE + 2]; Arrays.fill(header, (byte) 0); hex_len = ProtoCommon.long2buff(pkg_len); System.arraycopy(hex_len, 0, header, 0, hex_len.length); header[PROTO_HEADER_CMD_INDEX] = cmd; header[PROTO_HEADER_STATUS_INDEX] = errno; return header; }
/** * Upload file by file buff * @author Happy Fish / YuQing * @version Version 1.12 */ public static class UploadBuff implements UploadCallback { private byte[] fileBuff; private int offset; private int length; /** * constructor * @param fileBuff the file buff for uploading */ public UploadBuff(byte[] fileBuff, int offset, int length) { super(); this.fileBuff = fileBuff; this.offset = offset; this.length = length; } /** * send file content callback function, be called only once when the file uploaded * @param out output stream for writing file content * @return 0 success, return none zero(errno) if fail */ public int send(OutputStream out) throws IOException { out.write(this.fileBuff, this.offset, this.length); return 0; } }
/** * Upload file by file buff * @author Happy Fish / YuQing * @version Version 1.12 */ public static class UploadBuff implements UploadCallback { private byte[] fileBuff; private int offset; private int length; /** * constructor * @param fileBuff the file buff for uploading */ public UploadBuff(byte[] fileBuff, int offset, int length) { super(); this.fileBuff = fileBuff; this.offset = offset; this.length = length; } /** * send file content callback function, be called only once when the file uploaded * @param out output stream for writing file content * @return 0 success, return none zero(errno) if fail */ public int send(OutputStream out) throws IOException {
offset = header.length; hexLenBytes = ProtoCommon.long2buff(appender_filename.length()); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length; hexLenBytes = ProtoCommon.long2buff(file_offset); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length; hexLenBytes = ProtoCommon.long2buff(modify_size); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length;
offset = header.length; hexLenBytes = ProtoCommon.long2buff(appender_filename.length()); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length; hexLenBytes = ProtoCommon.long2buff(file_size); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length;
offset = header.length; hexLenBytes = ProtoCommon.long2buff(appender_filename.length()); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length; hexLenBytes = ProtoCommon.long2buff(file_size); System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length); offset += hexLenBytes.length;