blob: e6625614aad796e5c08e3758623843a92dc5800d [file] [log] [blame]
Francesco Furfariec7e1752006-10-02 13:37:04 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
Francesco Furfarid8bdb642006-04-04 23:33:40 +00009 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Francesco Furfarid8bdb642006-04-04 23:33:40 +000011 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000012 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
Francesco Furfarid8bdb642006-04-04 23:33:40 +000018 */
19
20package org.apache.felix.upnp.basedriver.importer.util;
21
22import java.io.*;
23import java.net.*;
24
Francesco Furfarif2a67912006-07-17 17:08:02 +000025/*
Karl Paulsd312acc2007-06-18 20:38:33 +000026* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Francesco Furfarif2a67912006-07-17 17:08:02 +000027*/
Francesco Furfarid8bdb642006-04-04 23:33:40 +000028public class HTTPRequestForIcon {
29 private URL url;
30
31 public HTTPRequestForIcon(URL url) {
32 this.url = url;
33 }
34 public InputStream getInputStream() throws IOException {
Francesco Furfarid8bdb642006-04-04 23:33:40 +000035 //TODO we should speak about that
36 InetAddress inet = InetAddress.getByName(url.getHost());
37 int port = url.getPort();
38 Socket socket = null;
39 socket = new Socket(inet, port);
40 OutputStream out = null;
41 out = socket.getOutputStream();
42 String CRLF = "\r\n";
43 url.getFile();
44 String request = "GET " + url.getPath() + " " + "HTTP/1.1" + CRLF
45 + "Host: " + url.getHost() + CRLF + "Connection: " + "close"
46 + CRLF + CRLF;
47 //System.out.println(request);
48 byte[] get = request.getBytes();
49 out.write(get, 0, get.length);
50 InputStream in = socket.getInputStream();
51 boolean exit = true;
52 while (exit) {
53 byte[] b = new byte[1];
54 in.read(b, 0, b.length);
55
56 if (b[0] == '\r') {
57 in.read(b, 0, b.length);
58 while (b[0] == '\r') {
59 in.read(b, 0, b.length);
60 }
61 if (b[0] != '\n') {
62 continue;
63 }
64 in.read(b, 0, b.length);
65 if (b[0] != '\r') {
66 continue;
67 }
68 in.read(b, 0, b.length);
69 if (b[0] != '\n') {
70 continue;
71 }
72 exit = false;
73 }
74 }
75
76 return in;
77
78 /*
Francesco Furfari0b466c72006-07-17 18:11:23 +000079 * HTTPResponse response=new HTTPResponse(in);
80 * InputStream iconInStream=response.getContentInputStream();
81 * return iconInStream;
Francesco Furfarid8bdb642006-04-04 23:33:40 +000082 *
83 */
84 /*
85 *
86 * byte[] buff = new byte[maxLength]; int initial = 0; while (initial <
87 * maxLength - 1) { int read = 0; read = in.read(buff, initial, 1024);
88 * if (read == -1) break; initial += read; } System.out.println(new
89 * String(buff));
90 */
91
92 }
93
Karl Paulsd312acc2007-06-18 20:38:33 +000094}