Debian Codegraph @

src/main/java/io/reactivex/rxjava3/disposables/AutoCloseableDisposable.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.disposables;
15
16 import io.reactivex.rxjava3.annotations.NonNull;
17 import io.reactivex.rxjava3.internal.util.ExceptionHelper;
18
19 /**
20 * A disposable container that manages an {@link AutoCloseable} instance.
21 * @since 3.0.0
22 */
23 final class AutoCloseableDisposable extends ReferenceDisposable<AutoCloseable> {
24
25 private static final long serialVersionUID = -6646144244598696847L;
26
27 AutoCloseableDisposable(AutoCloseable value) {
28 super(value);
29 }
30
31 @Override
32 protected void onDisposed(@NonNull AutoCloseable value) {
33 try {
34 value.close();
35 } catch (Throwable ex) {
36 throw ExceptionHelper.wrapOrThrow(ex);
37 }
38 }
39
40 @Override
41 public String toString() {
42 return "AutoCloseableDisposable(disposed=" + isDisposed() + ", " + get() + ")";
43 }
44
45 }