Back to project page Android-NetPowerctrl-Shared.
The source code is released under:
Copyright (c) 2014, David Gr?ff All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *...
If you think the Android project Android-NetPowerctrl-Shared listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package oly.netpowerctrl.device_base.device; //from w w w . j a v a 2 s.c om import android.support.annotation.NonNull; import android.util.JsonReader; import android.util.JsonWriter; import java.io.IOException; /** * A device connection for http */ public class DeviceConnectionHTTP extends DeviceConnection { public static final String ID = "HTTP"; // Device public int PortHttp = -1; public DeviceConnectionHTTP(Device device) { super(device); } /** * Create a new http connection with hostname and port that does not use default ports. * * @param device The device * @param hostName The hostname or IP * @param httpPort The http port */ public DeviceConnectionHTTP(Device device, String hostName, int httpPort) { super(device); this.mHostName = hostName; this.PortHttp = httpPort; } public void toJSON(JsonWriter writer) throws IOException { writer.beginObject(); writer.name("connection_type").value(ID); writer.name("HttpPort").value(PortHttp); writer.name("HostName").value(mHostName); writer.name("AllowHostnameUpdates").value(mIsAssignedByDevice); writer.endObject(); } @Override public boolean fromJSON(@NonNull JsonReader reader, boolean beginObjectAlreadyCalled) throws IOException, ClassNotFoundException { if (!beginObjectAlreadyCalled) reader.beginObject(); int members = 0; while (reader.hasNext()) { String name = reader.nextName(); assert name != null; switch (name) { case "HostName": mHostName = reader.nextString(); ++members; break; case "AllowHostnameUpdates": mIsAssignedByDevice = reader.nextBoolean(); ++members; break; case "HttpPort": PortHttp = reader.nextInt(); ++members; break; default: reader.skipValue(); break; } } reader.endObject(); return members >= 3; } @Override public int getDestinationPort() { return PortHttp; } @Override public String getProtocol() { return ID; } @Override public boolean equalsByDestinationAddress(DeviceConnection otherConnection, boolean lookupDNSName) { return cached_addresses == null ? mHostName.equals(otherConnection.mHostName) : hasAddress(otherConnection.getHostnameIPs(lookupDNSName), lookupDNSName); } @Override public int computeHash() { StringBuilder builder = new StringBuilder(); builder.append(ID); builder.append(PortHttp); builder.append(mHostName); return builder.toString().hashCode(); } }