use of java.net.ProtocolException in project android_frameworks_base by ParanoidAndroid.
the class NetworkStatsCollection method readLegacyNetwork.
@Deprecated
public void readLegacyNetwork(File file) throws IOException {
final AtomicFile inputFile = new AtomicFile(file);
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
// verify file magic header intact
final int magic = in.readInt();
if (magic != FILE_MAGIC) {
throw new ProtocolException("unexpected magic: " + magic);
}
final int version = in.readInt();
switch(version) {
case VERSION_NETWORK_INIT:
{
// network := size *(NetworkIdentitySet NetworkStatsHistory)
final int size = in.readInt();
for (int i = 0; i < size; i++) {
final NetworkIdentitySet ident = new NetworkIdentitySet(in);
final NetworkStatsHistory history = new NetworkStatsHistory(in);
final Key key = new Key(ident, UID_ALL, SET_ALL, TAG_NONE);
recordHistory(key, history);
}
break;
}
default:
{
throw new ProtocolException("unexpected version: " + version);
}
}
} catch (FileNotFoundException e) {
// missing stats is okay, probably first boot
} finally {
IoUtils.closeQuietly(in);
}
}
use of java.net.ProtocolException in project android_frameworks_base by ParanoidAndroid.
the class NetworkStatsCollection method read.
public void read(DataInputStream in) throws IOException {
// verify file magic header intact
final int magic = in.readInt();
if (magic != FILE_MAGIC) {
throw new ProtocolException("unexpected magic: " + magic);
}
final int version = in.readInt();
switch(version) {
case VERSION_UNIFIED_INIT:
{
// uid := size *(NetworkIdentitySet size *(uid set tag NetworkStatsHistory))
final int identSize = in.readInt();
for (int i = 0; i < identSize; i++) {
final NetworkIdentitySet ident = new NetworkIdentitySet(in);
final int size = in.readInt();
for (int j = 0; j < size; j++) {
final int uid = in.readInt();
final int set = in.readInt();
final int tag = in.readInt();
final Key key = new Key(ident, uid, set, tag);
final NetworkStatsHistory history = new NetworkStatsHistory(in);
recordHistory(key, history);
}
}
break;
}
default:
{
throw new ProtocolException("unexpected version: " + version);
}
}
}
use of java.net.ProtocolException in project java-apns by notnoop.
the class TlsTunnelBuilder method makeTunnel.
@SuppressFBWarnings(value = "VA_FORMAT_STRING_USES_NEWLINE", justification = "use <CR><LF> as according to RFC, not platform-linefeed")
Socket makeTunnel(String host, int port, String proxyUsername, String proxyPassword, InetSocketAddress proxyAddress) throws IOException {
if (host == null || port < 0 || host.isEmpty() || proxyAddress == null) {
throw new ProtocolException("Incorrect parameters to build tunnel.");
}
logger.debug("Creating socket for Proxy : " + proxyAddress.getAddress() + ":" + proxyAddress.getPort());
Socket socket;
try {
ProxyClient client = new ProxyClient();
client.getParams().setParameter("http.useragent", "java-apns");
client.getHostConfiguration().setHost(host, port);
String proxyHost = proxyAddress.getAddress().toString().substring(0, proxyAddress.getAddress().toString().indexOf("/"));
client.getHostConfiguration().setProxy(proxyHost, proxyAddress.getPort());
ProxyClient.ConnectResponse response = client.connect();
socket = response.getSocket();
if (socket == null) {
ConnectMethod method = response.getConnectMethod();
// Read the proxy's HTTP response.
if (method.getStatusLine().getStatusCode() == 407) {
// Proxy server returned 407. We will now try to connect with auth Header
if (proxyUsername != null && proxyPassword != null) {
socket = AuthenticateProxy(method, client, proxyHost, proxyAddress.getPort(), proxyUsername, proxyPassword);
} else {
throw new ProtocolException("Socket not created: " + method.getStatusLine());
}
}
}
} catch (Exception e) {
throw new ProtocolException("Error occurred while creating proxy socket : " + e.toString());
}
if (socket != null) {
logger.debug("Socket for proxy created successfully : " + socket.getRemoteSocketAddress().toString());
}
return socket;
}
use of java.net.ProtocolException in project OpenAM by OpenRock.
the class OpenAMUpgrade method getRequestToServer.
/**
* Talks to the OpenAM server
*
* @param readProgress Thread that prints out the current progress of the update
* @param openAmURL URL of the OpenAM instance to update
*
* @return true if update succeeds, false otherwise
*/
private boolean getRequestToServer(Thread readProgress, String openAmURL) {
DataOutputStream os = null;
BufferedReader br = null;
HttpURLConnection conn = null;
try {
URL url = new URL(openAmURL + "/config/upgrade/upgrade.htm?actionLink=doUpgrade&acceptLicense=" + acceptLicense);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(false);
conn.connect();
int responseCode = conn.getResponseCode();
if (responseCode == 200) {
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str;
while ((str = br.readLine()) != null) {
if (str.equals("true")) {
System.out.println("\nUpgrade Complete.");
} else {
System.out.println("\nUpgrade Failed. Please check the amUpgrade debug file for errors");
}
}
} else {
System.out.println(rb.getString("upgradeFailed"));
}
} catch (ProtocolException ex) {
ex.printStackTrace();
return false;
} catch (IOException ex) {
ex.printStackTrace();
return false;
} finally {
if (os != null) {
try {
os.close();
} catch (IOException ex) {
}
}
if (br != null) {
try {
br.close();
} catch (IOException ex) {
}
}
try {
// wait 5 seconds if ReadProgress thread does not finished.
readProgress.join(5000);
} catch (InterruptedException e) {
}
if (conn != null) {
try {
conn.disconnect();
} catch (Exception ex) {
}
}
}
return true;
}
use of java.net.ProtocolException in project android_frameworks_base by ResurrectionRemix.
the class IconCache method notifyIconReceived.
public void notifyIconReceived(long bssid, String fileName, byte[] iconData) {
Log.d("ZXZ", String.format("Icon '%s':%d received from %012x", fileName, iconData != null ? iconData.length : -1, bssid));
IconKey key;
HSIconFileElement iconFileElement = null;
List<OSUInfo> updates = new ArrayList<>();
LinkedList<QuerySet> querySets = mBssQueues.get(bssid);
if (querySets == null || querySets.isEmpty()) {
Log.d(OSUManager.TAG, String.format("Spurious icon response from %012x for '%s' (%d) bytes", bssid, fileName, iconData != null ? iconData.length : -1));
Log.d("ZXZ", "query set: " + querySets + ", BSS queues: " + Utils.bssidsToString(mBssQueues.keySet()));
return;
} else {
QuerySet querySet = querySets.removeFirst();
if (iconData != null) {
try {
iconFileElement = new HSIconFileElement(HSIconFile, ByteBuffer.wrap(iconData).order(ByteOrder.LITTLE_ENDIAN));
} catch (ProtocolException | BufferUnderflowException e) {
Log.e(OSUManager.TAG, "Failed to parse ANQP icon file: " + e);
}
}
key = querySet.updateIcon(fileName, iconFileElement);
if (key == null) {
Log.d(OSUManager.TAG, String.format("Spurious icon response from %012x for '%s' (%d) bytes", bssid, fileName, iconData != null ? iconData.length : -1));
Log.d("ZXZ", "query set: " + querySets + ", BSS queues: " + Utils.bssidsToString(mBssQueues.keySet()));
querySets.addFirst(querySet);
return;
}
if (iconFileElement != null) {
mCache.put(key, iconFileElement);
}
if (querySet.isEmpty()) {
mBssQueues.remove(bssid);
}
updates.add(querySet.getOsuInfo());
}
// Update any other pending entries that matches the ESS of the currently resolved icon
Iterator<Map.Entry<Long, LinkedList<QuerySet>>> bssIterator = mBssQueues.entrySet().iterator();
while (bssIterator.hasNext()) {
Map.Entry<Long, LinkedList<QuerySet>> bssEntries = bssIterator.next();
Iterator<QuerySet> querySetIterator = bssEntries.getValue().iterator();
while (querySetIterator.hasNext()) {
QuerySet querySet = querySetIterator.next();
if (querySet.updateIcon(key, iconFileElement)) {
querySetIterator.remove();
updates.add(querySet.getOsuInfo());
}
}
if (bssEntries.getValue().isEmpty()) {
bssIterator.remove();
}
}
initiateQuery(bssid);
mOSUManager.iconResults(updates);
}
Aggregations