File file = new File(localfile.getParent() + hexDecode(new File(GETfile).getAbsoluteFile().toString()) );
String LocalPath = new File(localfile.getParent()).toString(); File file = new File((LocalPath != null ? LocalPath : "") + hexDecode(new File(GETfile).getAbsoluteFile().toString()));
    private void serveTorrent(File localfile) {		ServerSocket server;				/* search for a free port we can bind to */		for (int i = 0; i <= 20; i++) {			try {				server = new ServerSocket(submitPort + i);				String link = "http://" + getMyIP() + ":" + server.getLocalPort() + "/" + localfile.getName() + ".torrent";				if (G2Gui.debug) System.out.println("INTERNAL HTTPD: " + link + " (waiting max " + SERVETIME + " seconds)");								sendLink(link);				/* is it dangerous to send the link before the internal httpd has been set up?				 * This could produce complications if the mld-core machine is really fast and				 * the local gui-machine is very very slow.				 * Multithreading this part is propably better in the future...	 */				try {					/* listen for incoming connections */					Socket socket = server.accept();					/* we got connected, proceed... */					try {						String GETfile = "";												if (G2Gui.debug) System.out.println("CONNECT: " + socket.toString());						BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));						PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);												/* read the first line to see if its a HTTP-request */						String string = in.readLine();						if (string.startsWith("GET")) {														/* which file does the other side request? */							if (RegExp.split(string, ' ').length > 1)  								GETfile = RegExp.split(string, ' ')[1];														/* remove our added trailing ".torrent" */							GETfile = GETfile.substring(0, GETfile.length() - ".torrent".length());														/* locate our local file */							File file = new File(localfile.getParent() + hexDecode(new File(GETfile).getAbsoluteFile().toString()) );							if (G2Gui.debug) System.out.println("REQUEST: " + GETfile + ", we should have it at: " + file);														if (file.exists()) {								out.println("HTTP/1.1 200 OK");								out.println("Server: G2gui Inbuilt Torrent Proxy");								out.println("Content-Type: application/x-bittorrent");								out.println("Content-Length: " + file.length());								/* after this empty line we can start the content-transmission */								out.println("");																/* read the file-contents */								byte[] b = new byte[(int) file.length()];								try {									FileInputStream fis = new FileInputStream(file);									fis.read(b);									fis.close();								} 								catch (FileNotFoundException e) { }								catch (IOException e) { }																/* send the file-contents to the socket */								FilterOutputStream contentout = new FilterOutputStream(socket.getOutputStream());								try {									contentout.write(b);								}								catch (IOException e) { }								if (G2Gui.debug) System.out.println("Torrent file served sucessfully!");							}						}							} finally {						socket.close();					}				} finally {					server.close();				}				/* when this break is reached, we sucessfully bound to a port */				break;			/* otherwise the for-loop will try with the next port */			} catch (IOException e) {				if (G2Gui.debug) System.out.println("Socket-binding exception: " + e);			}		}		    }