Here you can find the source of close(Object resource)
Parameter | Description |
---|---|
resource | to be closed. |
public static void close(Object resource)
//package com.java2s; /*/* w w w . j av a 2s .c om*/ * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: * */ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.RandomAccessFile; import java.io.Reader; import java.io.Writer; public class Main { /** * Closes the streams and resources. * * @param resource * to be closed. */ public static void close(Object resource) { try { if (resource instanceof InputStream) { ((InputStream) resource).close(); } else if (resource instanceof OutputStream) { ((OutputStream) resource).close(); } else if (resource instanceof Reader) { ((Reader) resource).close(); } else if (resource instanceof Writer) { ((Writer) resource).close(); } else if (resource instanceof RandomAccessFile) { ((RandomAccessFile) resource).close(); } else if (resource != null) { throw new IllegalArgumentException("Unknown resource: " + resource); } } catch (IOException e) { } } }