1 /*
2 * dpkg - Debian Package library and the Debian Package Maven plugin
3 * (c) Copyright 2015 Gerrit Hohl
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 package net.sourceforge.javadpkg.io.impl;
20
21 import java.io.Closeable;
22 import java.io.IOException;
23
24 import net.sourceforge.javadpkg.io.CloseHandler;
25
26 /**
27 * <p>
28 * A {@link CloseHandler} implementation which delegates the {@link #closed()}
29 * method call to the {@link Closeable#close()} method of a {@link Closeable}
30 * object.
31 * </p>
32 *
33 * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
34 * @version <b>1.0</b>, 31.12.2015 by Gerrit Hohl
35 */
36 public class DelegateCloseHandler implements CloseHandler {
37
38
39 /** The object which can be closed. */
40 private Closeable closeable;
41
42
43 /**
44 * <p>
45 * Creates a handler.
46 * </p>
47 *
48 * @param closeable
49 * The object which can be closed.
50 * @throws IllegalArgumentException
51 * If the object is <code>null</code>.
52 */
53 public DelegateCloseHandler(Closeable closeable) {
54 super();
55
56 if (closeable == null)
57 throw new IllegalArgumentException("Argument closeable is null.");
58
59 this.closeable = closeable;
60 }
61
62
63 @Override
64 public void closed() throws IOException {
65 this.closeable.close();
66 }
67
68
69 }