001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Florent Guillaume 016 */ 017package org.nuxeo.ecm.core.api; 018 019import java.io.Closeable; 020import java.io.File; 021import java.io.IOException; 022 023/** 024 * A wrapper for a {@link File}, which must be closed when done with it in order to release resources. 025 * 026 * @since 7.2 027 */ 028public class CloseableFile implements Closeable { 029 030 public final File file; 031 032 public final boolean deleteOnClose; 033 034 public CloseableFile(File file, boolean deleteOnClose) { 035 this.file = file; 036 this.deleteOnClose = deleteOnClose; 037 } 038 039 public File getFile() { 040 return file; 041 } 042 043 @Override 044 public void close() throws IOException { 045 if (deleteOnClose) { 046 file.delete(); 047 } 048 } 049}