/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package html_test; import java.io.File; /** * * @author H3R3T1C */ public class Packet { public Packet() { } public String creatHeader(int type,long size,String file_name,String f_type, String user)// type of data | Size of data | If its a file data sends { // file name else its a null byte | if file sends file type // based on int value (may change to string) String tmp=""; // user is string for now but will possibly change String padding="00";// used as a "null" byte // user is gotten from list of users in room if(!file_name.isEmpty()) tmp=numToHex(type)+padding+ numToHex(size)+padding+ StringtoHex(file_name)+ StringtoHex(f_type)+ StringtoHex(user); else tmp=numToHex(type)+padding+ numToHex(size)+padding+ StringtoHex(file_name)+ StringtoHex(f_type)+ StringtoHex(user); return tmp; } public byte[] createFilePacket(File file)// converts files into byte code for sending over internet { byte[] data={0};// whole thing = 0 (null) byte return data; } public byte[] createStringPacket(String string)// a diff method needs to be applyed { byte nul=0; byte[] tmp; return string.getBytes(); } public String StringtoHex(String data) { char[] chars = data.toCharArray(); StringBuffer output = new StringBuffer(); byte padding=0; for(int i = 0; i < chars.length; i++){ output.append(Integer.toHexString((int)chars[i])); } output.append(Integer.toHexString((int)padding)); output.append(Integer.toHexString((int)padding)); return output.toString(); } public String hexToString(String data) { char[] chars = data.toCharArray(); int z=0; String output=""; byte a=00; String tmp=""; for(int i = 0; i < chars.length; i+=2){ tmp=""+chars[i]+chars[i+1]; z=Integer.parseInt(tmp,16); output+=(char)z; } return output; } public String decodeHeader(String data) { String output=""; String tmp=""; int loc=0; char[] chars=data.toCharArray(); for(int a=0;a<2;a++) { for(int i=loc;i