Code Search for Developers
 
 
  

NetUtil.java from PeerWriter at Krugle


Show NetUtil.java syntax highlighted

package fr.loria.ecoo.util;

import java.io.ObjectOutputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;

import fr.loria.ecoo.wooki.web.Wooki;

public class NetUtil {
	public static int READ_TIME_OUT = 60000;

	public synchronized static void sendObjectViaHTTPRequest(URL url, Object object) throws Exception {
		HttpURLConnection init = (HttpURLConnection) url.openConnection();
		init.setConnectTimeout(READ_TIME_OUT);
		init.setReadTimeout(READ_TIME_OUT);
		init.setDoOutput(true);
		init.setUseCaches(false);
		init.setRequestProperty("Content-type", "application/octet-stream");
		ObjectOutputStream out = new ObjectOutputStream(init.getOutputStream());
		out.writeObject(object);
		out.flush();
		init.getResponseCode();
	}

	public synchronized static boolean testWookiSiteViaHTTPRequest(URL url) throws Exception {
		URL urlNeighbor = new URL(url + "?url=" + Wooki.getInstance().getWootSite().getId());
		HttpURLConnection init = (HttpURLConnection) urlNeighbor.openConnection();
		init.setConnectTimeout(READ_TIME_OUT);
		init.setReadTimeout(READ_TIME_OUT);
		init.setUseCaches(false);
		init.setRequestMethod("GET");
		if (init.getHeaderField("WOOKI_SERVICE") != null) {
			return true;
		}
		return false;
	}

	public static URL normalize(URL url) throws Exception {
		URI uri = url.toURI();
		uri = uri.normalize();
		String path = uri.getPath();
		if (!path.startsWith("/")) {
			path = "/" + path;
		}
		String urlStr = uri.getScheme() + "://" + uri.getHost();
		int port = uri.getPort();
		if (port != -1) {
			urlStr = urlStr + ":" + port;
		}
		urlStr = urlStr + path;
		return new URL(urlStr);
	}

}




See more files for this project here

PeerWriter

PeerWriter is a collaborative text editor. Multiple peers can edit the same document while they see overall changes in real-time. PeerWriter is based on a decentralized infrastructure, using a non-locking concurrency protocol ensuring global consistency.

Project homepage: http://sourceforge.net/projects/peerwriter
Programming language(s): Java,XML
License: gpl2

  log/
    Logger.java
    PrintLogger.java
  FileUtil.java
  GUID.java
  NetUtil.java
  ObjectCloner.java