ProxyProperties.java revision f6682b031742df794f95a3955db60595cb459b2a
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.net;
18
19
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.net.InetAddress;
24import java.net.UnknownHostException;
25
26/**
27 * A container class for the http proxy info
28 * @hide
29 */
30public class ProxyProperties implements Parcelable {
31
32    private InetAddress mProxy;
33    private int mPort;
34    private String mExclusionList;
35
36    public ProxyProperties() {
37    }
38
39    // copy constructor instead of clone
40    public ProxyProperties(ProxyProperties source) {
41        if (source != null) {
42            mProxy = source.getAddress();
43            mPort = source.getPort();
44            String exclusionList = source.getExclusionList();
45            if (exclusionList != null) {
46                mExclusionList = new String(exclusionList);
47            }
48        }
49    }
50
51    public InetAddress getAddress() {
52        return mProxy;
53    }
54
55    public void setAddress(InetAddress proxy) {
56        mProxy = proxy;
57    }
58
59    public int getPort() {
60        return mPort;
61    }
62
63    public void setPort(int port) {
64        mPort = port;
65    }
66
67    public String getExclusionList() {
68        return mExclusionList;
69    }
70
71    public void setExclusionList(String exclusionList) {
72        mExclusionList = exclusionList;
73    }
74
75    @Override
76    public String toString() {
77        StringBuilder sb = new StringBuilder();
78        if (mProxy != null) {
79            sb.append(mProxy.getHostAddress()).append(":").append(mPort);
80            if (mExclusionList != null) {
81                    sb.append(" xl=").append(mExclusionList);
82            }
83        }
84        return sb.toString();
85    }
86
87    /**
88     * Implement the Parcelable interface
89     * @hide
90     */
91    public int describeContents() {
92        return 0;
93    }
94
95    /**
96     * Implement the Parcelable interface.
97     * @hide
98     */
99    public void writeToParcel(Parcel dest, int flags) {
100        if (mProxy != null) {
101            dest.writeByte((byte)1);
102            dest.writeString(mProxy.getHostName());
103            dest.writeByteArray(mProxy.getAddress());
104        } else {
105            dest.writeByte((byte)0);
106        }
107        dest.writeInt(mPort);
108        dest.writeString(mExclusionList);
109    }
110
111    /**
112     * Implement the Parcelable interface.
113     * @hide
114     */
115    public static final Creator<ProxyProperties> CREATOR =
116        new Creator<ProxyProperties>() {
117            public ProxyProperties createFromParcel(Parcel in) {
118                ProxyProperties proxyProperties = new ProxyProperties();
119                if (in.readByte() == 1) {
120                    try {
121                        proxyProperties.setAddress(InetAddress.getByAddress(in.readString(),
122                                in.createByteArray()));
123                    } catch (UnknownHostException e) {}
124                }
125                proxyProperties.setPort(in.readInt());
126                proxyProperties.setExclusionList(in.readString());
127                return proxyProperties;
128            }
129
130            public ProxyProperties[] newArray(int size) {
131                return new ProxyProperties[size];
132            }
133        };
134}
135