Java Code Examples for java.io.Closeable#toString()

The following examples show how to use java.io.Closeable#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompositeStoppable.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static Stoppable toStoppable(final Object object) {
    if (object instanceof Stoppable) {
        return (Stoppable) object;
    }
    if (object instanceof Closeable) {
        final Closeable closeable = (Closeable) object;
        return new Stoppable() {
            @Override
            public String toString() {
                return closeable.toString();
            }

            public void stop() {
                try {
                    closeable.close();
                } catch (IOException e) {
                    throw UncheckedException.throwAsUncheckedException(e);
                }
            }
        };
    }
    return NO_OP_STOPPABLE;
}
 
Example 2
Source File: CompositeStoppable.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static Stoppable toStoppable(final Object object) {
    if (object instanceof Stoppable) {
        return (Stoppable) object;
    }
    if (object instanceof Closeable) {
        final Closeable closeable = (Closeable) object;
        return new Stoppable() {
            @Override
            public String toString() {
                return closeable.toString();
            }

            public void stop() {
                try {
                    closeable.close();
                } catch (IOException e) {
                    throw UncheckedException.throwAsUncheckedException(e);
                }
            }
        };
    }
    return NO_OP_STOPPABLE;
}
 
Example 3
Source File: BenchmarkBase.java    From cache2k-benchmark with Apache License 2.0 5 votes vote down vote up
public void closeIfNeeded(final Closeable _closeable) {
  if (_closeable != null) {
    System.out.println();
    String _statString = _closeable.toString();
    System.out.println(_statString);
    System.out.println("availableProcessors: " + Runtime.getRuntime().availableProcessors());
    try {
      _closeable.close();
    } catch (IOException _ignore) {
    }
  }
}