comparison cmdline/org/tmatesoft/hg/console/Remote.java @ 156:643ddec3be36

Investigate pull/clone functionality
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 02 Mar 2011 01:06:09 +0100
parents 6b55f10ef54b
children 86f9581f4301
comparison
equal deleted inserted replaced
155:a4ec5e087017 156:643ddec3be36
16 */ 16 */
17 package org.tmatesoft.hg.console; 17 package org.tmatesoft.hg.console;
18 18
19 import java.io.File; 19 import java.io.File;
20 import java.io.FileOutputStream; 20 import java.io.FileOutputStream;
21 import java.io.IOException;
21 import java.io.InputStream; 22 import java.io.InputStream;
23 import java.net.HttpURLConnection;
22 import java.net.URL; 24 import java.net.URL;
23 import java.security.cert.CertificateException; 25 import java.security.cert.CertificateException;
24 import java.security.cert.X509Certificate; 26 import java.security.cert.X509Certificate;
25 import java.util.List; 27 import java.util.List;
26 import java.util.Map; 28 import java.util.Map;
54 */ 56 */
55 public static void main(String[] args) throws Exception { 57 public static void main(String[] args) throws Exception {
56 ConfigFile cfg = new Internals().newConfigFile(); 58 ConfigFile cfg = new Internals().newConfigFile();
57 cfg.addLocation(new File(System.getProperty("user.home"), ".hgrc")); 59 cfg.addLocation(new File(System.getProperty("user.home"), ".hgrc"));
58 String svnkitServer = cfg.getSection("paths").get("svnkit"); 60 String svnkitServer = cfg.getSection("paths").get("svnkit");
59 URL url = new URL(svnkitServer + "?cmd=changegroup&roots=a78c980749e3ccebb47138b547e9b644a22797a9"); 61 // URL url = new URL(svnkitServer + "?cmd=changegroup&roots=a78c980749e3ccebb47138b547e9b644a22797a9");
62 // URL url = new URL("http://localhost:8000/" + "?cmd=stream_out");
63 URL url = new URL(svnkitServer + "?cmd=stream_out");
60 64
61 SSLContext sslContext = SSLContext.getInstance("SSL"); 65 SSLContext sslContext = SSLContext.getInstance("SSL");
62 class TrustEveryone implements X509TrustManager { 66 class TrustEveryone implements X509TrustManager {
63 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 67 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
64 System.out.println("checkClientTrusted " + authType); 68 System.out.println("checkClientTrusted " + authType);
68 } 72 }
69 public X509Certificate[] getAcceptedIssuers() { 73 public X509Certificate[] getAcceptedIssuers() {
70 return new X509Certificate[0]; 74 return new X509Certificate[0];
71 } 75 }
72 } 76 }
73 // 77 // Hack to get Base64-encoded credentials
74 Preferences tempNode = Preferences.userRoot().node("xxx"); 78 Preferences tempNode = Preferences.userRoot().node("xxx");
75 tempNode.putByteArray("xxx", url.getUserInfo().getBytes()); 79 tempNode.putByteArray("xxx", url.getUserInfo().getBytes());
76 String authInfo = tempNode.get("xxx", null); 80 String authInfo = tempNode.get("xxx", null);
77 tempNode.removeNode(); 81 tempNode.removeNode();
78 // 82 //
88 for (String s : headerFields.keySet()) { 92 for (String s : headerFields.keySet()) {
89 System.out.printf("%s: %s\n", s, urlConnection.getHeaderField(s)); 93 System.out.printf("%s: %s\n", s, urlConnection.getHeaderField(s));
90 } 94 }
91 System.out.printf("Content type is %s and its length is %d\n", urlConnection.getContentType(), urlConnection.getContentLength()); 95 System.out.printf("Content type is %s and its length is %d\n", urlConnection.getContentType(), urlConnection.getContentLength());
92 InputStream is = urlConnection.getInputStream(); 96 InputStream is = urlConnection.getInputStream();
93 // int b; 97 //
94 // while ((b =is.read()) != -1) { 98 dump(is, -1); // simple dump, any cmd
95 // System.out.print((char) b); 99 // writeBundle(is); // cmd=changegroup
96 // } 100 //
97 // System.out.println(); 101 urlConnection.disconnect();
102 //
103 }
104
105 private static void dump(InputStream is, int limit) throws IOException {
106 int b;
107 while ((b =is.read()) != -1) {
108 System.out.print((char) b);
109 if (limit != -1) {
110 if (--limit < 0) {
111 break;
112 }
113 }
114 }
115 System.out.println();
116 }
117
118 private static void writeBundle(InputStream is) throws IOException {
98 InflaterInputStream zipStream = new InflaterInputStream(is); 119 InflaterInputStream zipStream = new InflaterInputStream(is);
99 File tf = File.createTempFile("hg-bundle-", null); 120 File tf = File.createTempFile("hg-bundle-", null);
100 FileOutputStream fos = new FileOutputStream(tf); 121 FileOutputStream fos = new FileOutputStream(tf);
101 int r; 122 int r;
102 byte[] buf = new byte[8*1024]; 123 byte[] buf = new byte[8*1024];
104 fos.write(buf, 0, r); 125 fos.write(buf, 0, r);
105 } 126 }
106 fos.close(); 127 fos.close();
107 zipStream.close(); 128 zipStream.close();
108 System.out.println(tf); 129 System.out.println(tf);
109
110 urlConnection.disconnect();
111 //
112 } 130 }
113 } 131 }