📄 util.java
字号:
package net.benhui.btgallery;
import javax.bluetooth.*;
//import javax.obex.*;
import java.util.Enumeration;
import java.io.IOException;
import java.util.*;
/**
* <p>Title: A utility class to dump JABWT object contents</p>
* <p>Description: A collection of print utility method that output the attributes of JABWT objects to System.out
* Supported objects are: <br>
* LocalDevice<br>
* RemoteDevice<br>
* DeviceClass<br>
* UUID<br>
* ServiceRecord<br>
* DataElement<br>
* Major Service Class <br>
* Major, Minor Device Class<br
* Attribute ID<br>
* OBEXHeader (incomplete)<br>
* </p>
* <p>Copyright: Copyright (c) 2003</p>
* @author Ben Hui
* @version 1.0
*/
public class Util
{
private Util()
{
}
public static void printRemoteDevice( RemoteDevice dev, DeviceClass devClass )
{
try
{
System.out.println("Print Remote Device "+dev.getBluetoothAddress());
System.out.println("Name: "+dev.getFriendlyName( false ) );
System.out.println("Auth: "+dev.isAuthenticated()+" Encrypted: "+dev.isEncrypted()+" Trusted: "+dev.isTrustedDevice() );
if ( devClass != null )
{
System.out.println("MajorDevice:" +
majorToName(devClass.getMajorDeviceClass()));
System.out.println("MinorDevice:" +
minorToName(devClass.getMajorDeviceClass(),
devClass.getMinorDeviceClass()));
System.out.println("ServiceClass:");
String[] str = Util.majorServiceToName(devClass.getServiceClasses());
for (int i = 0; i < str.length; i++) {
System.out.println(" " + str[i]);
}
}
} catch (IOException e)
{
}
}
public static void printLocalDevice( LocalDevice dev )
{
System.out.println("Print Local Device "+dev.getBluetoothAddress());
System.out.println("Name: "+dev.getFriendlyName());
DeviceClass devClass = dev.getDeviceClass();
if ( devClass != null )
{
System.out.println("MajorDevice:" +
majorToName(devClass.getMajorDeviceClass()));
System.out.println("MinorDevice:" +
minorToName(devClass.getMajorDeviceClass(),
devClass.getMinorDeviceClass()));
System.out.println("ServiceClass:");
String[] str = Util.majorServiceToName(devClass.getServiceClasses());
for (int i = 0; i < str.length; i++) {
System.out.println(" " + str[i]);
}
}
}
/*
public static void printDeviceClass( DeviceClass d )
{
System.out.println("Print Device Class "+d.toString());
}
*/
public static void printServiceRecord( ServiceRecord r )
{
int[] ids = r.getAttributeIDs();
System.out.println("Print Service Record (# of element: "+ids.length+")");
System.out.println("Print Service Record URL "+r.getConnectionURL( ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false ) );
for ( int i=0; i < ids.length; i++ )
{
DataElement el = r.getAttributeValue( ids[i] );
printDataElement( el, ids[i], "" );
}
}
public static void printDataElement( DataElement e, int id, String indent )
{
int type = e.getDataType();
if ( type == DataElement.DATALT || type == DataElement.DATSEQ )
{
Enumeration enum = (Enumeration)e.getValue();
System.out.println(indent+"DataElement["+idToName(id)+"] "+type+" (# of element: "+e.getSize()+")");
while ( enum.hasMoreElements() )
{
DataElement e2 = (DataElement)enum.nextElement();
printDataElement( e2, id, indent+" " );
}
} else if ( type == DataElement.U_INT_1 || type == DataElement.U_INT_2 || type == DataElement.U_INT_4 ||
type == DataElement.INT_1 || type == DataElement.INT_2 || type == DataElement.INT_4 || type == DataElement.INT_8 )
{
long v = e.getLong();
System.out.println(indent+"DataElement["+idToName(id)+"] "+v);
} else if ( type == DataElement.UUID )
{
UUID uuid = (UUID) e.getValue();
System.out.println(indent+"DataElement["+idToName(id)+"] "+ uuidToName(uuid) );
} else if ( type == DataElement.U_INT_8 || type == DataElement.U_INT_16 || type == DataElement.INT_16 )
{
byte[] v = (byte[]) e.getValue();
String s = "";
for ( int i=0; i< v.length; i++ )
{
s+= Integer.toHexString( (int) v[i] );
}
System.out.println(indent+"DataElement["+idToName(id)+"] "+s );
} else if ( type == DataElement.STRING || type == DataElement.URL )
{
String v = (String) e.getValue();
System.out.println(indent+"DataElement["+idToName(id)+"] "+v );
} else if ( type == DataElement.BOOL )
{
boolean v = e.getBoolean();
System.out.println(indent+"DataElement["+idToName(id)+"] "+ String.valueOf( v));
} else if ( type == DataElement.NULL )
{
System.out.println(indent+"DataElement["+idToName(id)+"] NULL");
}
}
// convert Attribute ID to human friendly name
public static String idToName( int id )
{
if ( id == 0x0000 )
{
return "ServiceRecordHandle";
} else if ( id == 0x0001 )
{
return "ServiceClassIDList";
} else if ( id == 0x0002 )
{
return "ServiceRecordState";
} else if ( id == 0x0003 )
{
return "ServiceID";
} else if ( id == 0x0004 )
{
return "ProtocolDescriptorList";
} else if ( id == 0x0005 )
{
return "BrowseGroupList";
} else if ( id == 0x0006 )
{
return "LanguageBasedAttributeIDList";
} else if ( id == 0x0007 )
{
return "ServiceInfoTimeToLive";
} else if ( id == 0x0008 )
{
return "ServiceAvailability";
} else if ( id == 0x0009 )
{
return "BluetoothProfileDescriptorList";
} else if ( id == 0x000A )
{
return "DocumentationURL";
} else if ( id == 0x000B )
{
return "ClientExecutableURL";
} else if ( id == 0x000C )
{
return "IconURL";
} else if ( id == 0x000D )
{
return "AdditionalProtocol";
} else if ( id == 0x0100 )
{
return "ServiceName";
} else if ( id == 0x0101 )
{
return "ServiceDescription";
} else if ( id == 0x0102 )
{
return "ProviderName";
} else if ( id == 0x0200 )
{
/** @todo why the spec say it is GroupID, IpSubnet and VersionNumberList as well? */
return "GroupID";
} else if ( id == 0x0201 )
{
return "ServiceDatabaseState";
} else if ( id == 0x0300 )
{
return "ServiceVersion";
} else if ( id == 0x0301 )
{
return "ExternalNetwork";
} else if ( id == 0x0302 )
{
// @todo or FaxClass1Support in case of Fax Profile
return "RemoteAudioVolumeControl";
} else if ( id == 0x0303 )
{
// @todo or FaxClass2Support in case of Fax Profile
return "SupportedFormatList";
} else if ( id == 0x0304 )
{
return "FaxClass2Support";
} else if ( id == 0x0305 )
{
return "AudioFeedbackSupport";
} else if ( id == 0x0306 )
{
return "NetworkAddress";
} else if ( id == 0x0307 )
{
return "WAPGateway";
} else if ( id == 0x0308 )
{
return "HomePageURL";
} else if ( id == 0x0309 )
{
return "WAPStackType";
} else if ( id == 0x030A )
{
return "SecurityDescription";
} else if ( id == 0x030B )
{
return "NetAccessType";
} else if ( id == 0x030C )
{
return "MaxNetAccessrate";
} else if ( id == 0x030D )
{
return "IPv4Subnet";
} else if ( id == 0x030E )
{
return "IPv6Subnet";
} else if ( id == 0x0310 )
{
return "SupportedCapabalities";
} else if ( id == 0x0311 )
{
return "SupportedFeatures";
} else if ( id == 0x0312 )
{
return "SupportedFunctions";
} else if ( id == 0x0313 )
{
return "TotalImagingDataCapacity";
} else
{
return "UnknownAttribute("+id+")";
}
}
public static String uuidToName( UUID u )
{
if ( u.equals( new UUID( 0x0001 ) ))
return "SDP";
else if ( u.equals( new UUID( 0x0003 ) ))
return "RFCOMM";
else if ( u.equals( new UUID( 0x0008 ) ))
return "OBEX";
else if ( u.equals( new UUID( 0x000C ) ))
return "HTTP";
else if ( u.equals( new UUID( 0x0100 ) ))
return "L2CAP";
else if ( u.equals( new UUID( 0x000F ) ))
return "BNEP";
else if ( u.equals( new UUID( 0x1000 ) ))
return "ServiceDiscoveryServerServiceClassID";
else if ( u.equals( new UUID( 0x1001 ) ))
return "BrowseGroupDescriptorCerviceClassID";
else if ( u.equals( new UUID( 0x1002 ) ))
return "PublicBrowseGroup";
else if ( u.equals( new UUID( 0x1101 ) ))
return "SerialPort";
else if ( u.equals( new UUID( 0x1102 ) ))
return "LANAccessUsingPPP";
else if ( u.equals( new UUID( 0x1103 ) ))
return "DialupNetworking";
else if ( u.equals( new UUID( 0x1104 ) ))
return "IrMCSync";
else if ( u.equals( new UUID( 0x1105 ) ))
return "OBEX ObjectPushProfile";
else if ( u.equals( new UUID( 0x1106 ) ))
return "OBEX FileTrasnferProfile";
else if ( u.equals( new UUID( 0x1107 ) ))
return "IrMCSyncCommand";
else if ( u.equals( new UUID( 0x1108 ) ))
return "Headset";
else if ( u.equals( new UUID( 0x1109 ) ))
return "CordlessTelephony";
else if ( u.equals( new UUID( 0x110A ) ))
return "AudioSource";
else if ( u.equals( new UUID( 0x1111 ) ))
return "Fax";
else if ( u.equals( new UUID( 0x1112 ) ))
return "HeadsetAudioGateway";
else if ( u.equals( new UUID( 0x1115 ) ))
return "PersonalAreaNetworkingUser";
else if ( u.equals( new UUID( 0x1116 ) ))
return "NetworkAccessPoint";
else if ( u.equals( new UUID( 0x1117 ) ))
return "GroupNetwork";
else if ( u.equals( new UUID( 0x111E ) ))
return "Handsfree";
else if ( u.equals( new UUID( 0x111F ) ))
return "HandsfreeAudioGateway";
else if ( u.equals( new UUID( 0x1201 ) ))
return "GenericNetworking";
else if ( u.equals( new UUID( 0x1202 ) ))
return "GenericFileTransfer";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -