File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,22 @@ Library like J2ME's Connector.open() but with TLS 1.2 automatically.
44### Usage
55HTTPS:
66``` java
7+ // Somewhere
8+ private static byte [] readAll(InputStream in, int max) throws IOException {
9+ ByteArrayOutputStream bos = new ByteArrayOutputStream ();
10+ byte [] buf = new byte [512 ];
11+ int total = 0 ;
12+ while (true ) {
13+ int want = Math . min(buf. length, max - total);
14+ if (want <= 0 ) break ;
15+ int n = in. read(buf, 0 , want);
16+ if (n == - 1 ) break ;
17+ bos. write(buf, 0 , n);
18+ total += n;
19+ }
20+ return bos. toByteArray();
21+ }
22+
723HttpConnection hc = (HttpConnection ) ModernConnector . open(" https://cloudflare.com/cdn-cgi/trace" );
824hc. setRequestMethod(HttpConnection . GET );
925hc. setRequestProperty(" Accept" , " */*" );
You can’t perform that action at this time.
0 commit comments