88
99/**
1010 * Helper methods for using sun.misc.Unsafe.
11+ *
1112 * @author Taro L. Saito
1213 */
1314public class UnsafeUtil {
@@ -17,9 +18,11 @@ public static Unsafe getUnsafe() {
1718 Field f = Unsafe .class .getDeclaredField ("theUnsafe" );
1819 f .setAccessible (true );
1920 return Unsafe .class .cast (f .get (null ));
20- } catch (NoSuchFieldException e ) {
21+ }
22+ catch (NoSuchFieldException e ) {
2123 throw new IllegalStateException ("sun.misc.Unsafe is not available in this JVM" );
22- } catch (IllegalAccessException e ) {
24+ }
25+ catch (IllegalAccessException e ) {
2326 throw new IllegalStateException ("sun.misc.Unsafe is not available in this JVM" );
2427 }
2528 }
@@ -29,9 +32,11 @@ public static Unsafe getUnsafe() {
2932 private static Constructor <?> findDirectByteBufferConstructor () {
3033 try {
3134 return Class .forName ("java.nio.DirectByteBuffer" ).getDeclaredConstructor (Long .TYPE , Integer .TYPE , Object .class );
32- } catch (ClassNotFoundException e ) {
35+ }
36+ catch (ClassNotFoundException e ) {
3337 throw new IllegalStateException (String .format ("Failed to find java.nio.DirectByteBuffer: $s" , e .getMessage ()));
34- } catch (NoSuchMethodException e ) {
38+ }
39+ catch (NoSuchMethodException e ) {
3540 throw new IllegalStateException (String .format ("Failed to find constructor f java.nio.DirectByteBuffer: $s" , e .getMessage ()));
3641 }
3742 }
@@ -44,9 +49,9 @@ private static Constructor<?> findDirectByteBufferConstructor() {
4449 *
4550 * @param addr
4651 * @param size
47- * @param att object holding the underlying memory to attach to the buffer.
48- * This will prevent the garbage collection of the memory area that's
49- * associated with the new <code>DirectByteBuffer</code>
52+ * @param att object holding the underlying memory to attach to the buffer.
53+ * This will prevent the garbage collection of the memory area that's
54+ * associated with the new <code>DirectByteBuffer</code>
5055 * @return
5156 */
5257 public static ByteBuffer newDirectByteBuffer (long addr , int size , Object att ) {
@@ -55,7 +60,8 @@ public static ByteBuffer newDirectByteBuffer(long addr, int size, Object att) {
5560 try {
5661 b = dbbCC .newInstance (new Long (addr ), new Integer (size ), att );
5762 return ByteBuffer .class .cast (b );
58- } catch (Exception e ) {
63+ }
64+ catch (Exception e ) {
5965 throw new IllegalStateException (String .format ("Failed to create DirectByteBuffer: %s" , e .getMessage ()));
6066 }
6167 }
0 commit comments