import com.jkristian.io.ByteCopier; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; public class ReadURLs { /** * Copy headers and data from the given URLs to System.out. Supports p4 * URLs, as well as any other URL schemes supported by Java or installed in * the JVM. * * @see com.perforce.api.protocol.p4.Handler */ public static void main(String[] URLs) throws Exception { com.perforce.api.protocol.p4.Handler.install(); // support p4 URLs for (int u = 0; u < URLs.length; ++u) { URL url = new URL(URLs[u]); URLConnection connection = url.openConnection(); for (int h = 0; true; ++h) { String name = connection.getHeaderFieldKey(h); String value = connection.getHeaderField(h); if (value == null) break; if (name == null) System.out.println(value); else System.out.println(name + ": " + value); } System.out.println(); InputStream data = connection.getInputStream(); try { ByteCopier.copyAll(data, System.out); } finally { data.close(); } System.out.println(); System.out.println("-------------------"); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 5051 | John Kristian | added an example | ||
//guest/john_kristian/p4package/com/perforce/api/protocol/p4/Handler.java | |||||
#1 | 5047 | John Kristian |
This version builds and runs. It depends on Java 1.4 and com.jkristian.io. |
||
//guest/john_kristian/p4URL/src/com/jkristian/protocol/p4/Handler.java | |||||
#12 | 5023 | John Kristian | upgraded to io-v0_3 | ||
#11 | 5022 | John Kristian | beefed up newline handling | ||
#10 | 5021 | John Kristian | cross-reference the I/O packages (from SourceForge) | ||
#9 | 5020 | John Kristian | method renamed | ||
#8 | 5018 | John Kristian |
Refined getContentType algorithm. Don't ignore IOException. |
||
#7 | 5017 | John Kristian | add a charset only if p4Type.endsWith("unicode") | ||
#6 | 5016 | John Kristian | added Content-Type header | ||
#5 | 5015 | John Kristian | commentary | ||
#4 | 5014 | John Kristian | refined | ||
#3 | 5008 | John Kristian | Don't normalize //depot to /depot. | ||
#2 | 5007 | John Kristian |
Handle relative URIs (e.g. ../package.dtd). |
||
#1 | 5006 | John Kristian | Enable URL-based Java applications to get files from a Perforce depot. |