forked from geodmms/xdgnjobs

Dennis Kao
2014-01-15 94ae08701bbd7585a0b7e5a92d1975965a503c03
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/NIOUtilities.java
@@ -34,8 +34,7 @@
 * @source $URL$
 * @since 2.0
 */
public class NIOUtilities
{
public class NIOUtilities {
    /**
     * {@code true} if a warning has already been logged.
     */
@@ -47,8 +46,7 @@
     * @todo This constructor will become private when {@code NIOBufferUtils}
     * will have been removed.
     */
    protected NIOUtilities()
    {
    protected NIOUtilities() {
    }
    /**
@@ -61,30 +59,23 @@
     * @return true if the operation was successful, false otherwise.
     * @see java.nio.MappedByteBuffer
     */
    public static boolean clean(final ByteBuffer buffer)
    {
        if (buffer == null || !buffer.isDirect())
        {
    public static boolean clean(final ByteBuffer buffer) {
        if (buffer == null || !buffer.isDirect()) {
            return false;
        }
        Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction()
        {
            public Object run()
            {
        Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                Boolean success = Boolean.FALSE;
                try
                {
                try {
                    Method getCleanerMethod = buffer.getClass().getMethod("cleaner", (Class[]) null);
                    getCleanerMethod.setAccessible(true);
                    Object cleaner = getCleanerMethod.invoke(buffer, (Object[]) null);
                    Method clean = cleaner.getClass().getMethod("clean", (Class[]) null);
                    clean.invoke(cleaner, (Object[]) null);
                    success = Boolean.TRUE;
                } catch (Exception e)
                {
                } catch (Exception e) {
                    // This really is a show stopper on windows
                    if (isLoggable())
                    {
                    if (isLoggable()) {
                        log(e, buffer);
                    }
                }
@@ -98,15 +89,12 @@
    /**
     * Check if a warning message should be logged.
     */
    private static synchronized boolean isLoggable()
    {
        try
        {
    private static synchronized boolean isLoggable() {
        try {
            return !warned && (
                    System.getProperty("org.geotools.io.debugBuffer", "false").equalsIgnoreCase("true") ||
                            System.getProperty("os.name").indexOf("Windows") >= 0);
        } catch (SecurityException exception)
        {
                System.getProperty("org.geotools.io.debugBuffer", "false").equalsIgnoreCase("true") ||
                    System.getProperty("os.name").indexOf("Windows") >= 0);
        } catch (SecurityException exception) {
            // The utilities may be running in an Applet, in which case we
            // can't read properties. Assumes we are not in debugging mode.
            return false;
@@ -116,12 +104,11 @@
    /**
     * Log a warning message.
     */
    private static synchronized void log(final Exception e, final ByteBuffer buffer)
    {
    private static synchronized void log(final Exception e, final ByteBuffer buffer) {
        warned = true;
        String message = "Error attempting to close a mapped byte buffer : " + buffer.getClass().getName()
                + "\n JVM : " + System.getProperty("java.version")
                + ' ' + System.getProperty("java.vendor");
            + "\n JVM : " + System.getProperty("java.version")
            + ' ' + System.getProperty("java.vendor");
        Logger.getLogger("org.geotools.io").log(Level.SEVERE, message, e);
    }
}