2323import javax .usb .UsbDeviceDescriptor ;
2424import javax .usb .UsbDisconnectedException ;
2525import javax .usb .UsbException ;
26+ import javax .usb .UsbPlatformException ;
2627import javax .usb .UsbPort ;
2728import javax .usb .UsbStringDescriptor ;
2829import javax .usb .event .UsbDeviceEvent ;
@@ -99,12 +100,12 @@ abstract class AbstractDevice implements UsbDevice
99100 * The libusb device. This reference is only valid during the
100101 * constructor execution, so don't store it in a property or
101102 * something like that.
102- * @throws LibUsbException
103+ * @throws UsbPlatformException
103104 * When device configuration could not be read.
104105 */
105106 AbstractDevice (final DeviceManager manager , final DeviceId id ,
106107 final DeviceId parentId , final int speed , final Device device )
107- throws LibUsbException
108+ throws UsbPlatformException
108109 {
109110 if (manager == null )
110111 throw new IllegalArgumentException ("manager must be set" );
@@ -126,8 +127,9 @@ abstract class AbstractDevice implements UsbDevice
126127 configDescriptor );
127128 if (result < 0 )
128129 {
129- throw new LibUsbException ("Unable to get configuation " + i
130- + " for device " + id , result );
130+ throw ExceptionUtils .createPlatformException (
131+ "Unable to get configuation " + i + " for device " + id ,
132+ result );
131133 }
132134 try
133135 {
@@ -159,7 +161,7 @@ abstract class AbstractDevice implements UsbDevice
159161 }
160162 else if (result < 0 )
161163 {
162- throw new LibUsbException (
164+ throw ExceptionUtils . createPlatformException (
163165 "Unable to read active config descriptor from device " + id ,
164166 result );
165167 }
@@ -221,8 +223,8 @@ public final DeviceHandle open() throws UsbException
221223 final int result = LibUsb .open (device , handle );
222224 if (result < 0 )
223225 {
224- throw new LibUsbException ( "Can't open device "
225- + this .id , result );
226+ throw ExceptionUtils . createPlatformException (
227+ "Can't open device " + this .id , result );
226228 }
227229 this .handle = handle ;
228230 }
@@ -379,8 +381,8 @@ final void setActiveUsbConfigurationNumber(final byte number)
379381
380382 final int result = LibUsb .setConfiguration (open (), number & 0xff );
381383 if (result < 0 )
382- throw new LibUsbException ( "Unable to set configuration" ,
383- result );
384+ throw ExceptionUtils . createPlatformException (
385+ "Unable to set configuration" , result );
384386 this .activeConfigurationNumber = number ;
385387 }
386388 }
@@ -414,16 +416,20 @@ final void claimInterface(final byte number, final boolean force)
414416 {
415417 result = LibUsb .detachKernelDriver (handle , number );
416418 if (result < 0 )
417- throw new LibUsbException (
419+ {
420+ throw ExceptionUtils .createPlatformException (
418421 "Unable to detach kernel driver" , result );
422+ }
419423 this .detachedKernelDriver = true ;
420424 }
421425 }
422426
423427 final int result = LibUsb .claimInterface (handle , number & 0xff );
424428 if (result < 0 )
425- throw new LibUsbException ("Unable to claim interface" ,
426- result );
429+ {
430+ throw ExceptionUtils .createPlatformException (
431+ "Unable to claim interface" , result );
432+ }
427433 this .claimedInterfaceNumbers .add (number );
428434 }
429435
@@ -444,14 +450,20 @@ final void releaseInterface(final byte number) throws UsbException
444450
445451 final DeviceHandle handle = open ();
446452 int result = LibUsb .releaseInterface (handle , number & 0xff );
447- if (result < 0 ) throw new LibUsbException (
448- "Unable to release interface" , result );
453+ if (result < 0 )
454+ {
455+ throw ExceptionUtils .createPlatformException (
456+ "Unable to release interface" , result );
457+ }
449458
450459 if (this .detachedKernelDriver )
451460 {
452461 result = LibUsb .attachKernelDriver (handle , number & 0xff );
453- if (result < 0 ) throw new LibUsbException (
454- "Uanble to re-attach kernel driver" , result );
462+ if (result < 0 )
463+ {
464+ throw ExceptionUtils .createPlatformException (
465+ "Uanble to re-attach kernel driver" , result );
466+ }
455467 }
456468
457469 this .claimedInterfaceNumbers .remove (number );
@@ -499,8 +511,11 @@ public final UsbStringDescriptor getUsbStringDescriptor(final byte index)
499511 final int result =
500512 LibUsb .getStringDescriptor (handle , index , langId , data );
501513 if (result < 0 )
502- throw new LibUsbException ("Unable to get string descriptor "
503- + index + " from device " + this , result );
514+ {
515+ throw ExceptionUtils .createPlatformException (
516+ "Unable to get string descriptor " + index + " from device "
517+ + this , result );
518+ }
504519 return new SimpleUsbStringDescriptor (data );
505520 }
506521
@@ -525,8 +540,10 @@ private short[] getLanguages() throws UsbException
525540 final int result = LibUsb .getDescriptor (handle , LibUsb .DT_STRING ,
526541 (byte ) 0 , buffer );
527542 if (result < 0 )
528- throw new LibUsbException (
543+ {
544+ throw ExceptionUtils .createPlatformException (
529545 "Unable to get string descriptor languages" , result );
546+ }
530547 if (result < 2 )
531548 throw new UsbException ("Received illegal descriptor length: "
532549 + result );
0 commit comments