comparison src/org/eclipse/jetty/util/component/FileDestroyable.java @ 802:3428c60d7cfc

replace jetty jars with source
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 07 Sep 2016 21:15:48 -0600
parents
children 8e9db0bbf4f9
comparison
equal deleted inserted replaced
801:6a21393191c1 802:3428c60d7cfc
1 //
2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.util.component;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26
27 import org.eclipse.jetty.util.IO;
28 import org.eclipse.jetty.util.log.Log;
29 import org.eclipse.jetty.util.log.Logger;
30 import org.eclipse.jetty.util.resource.Resource;
31
32 public class FileDestroyable implements Destroyable
33 {
34 private static final Logger LOG = Log.getLogger(FileDestroyable.class);
35 final List<File> _files = new ArrayList<File>();
36
37 public FileDestroyable()
38 {
39 }
40
41 public FileDestroyable(String file) throws IOException
42 {
43 _files.add(Resource.newResource(file).getFile());
44 }
45
46 public FileDestroyable(File file)
47 {
48 _files.add(file);
49 }
50
51 public void addFile(String file) throws IOException
52 {
53 _files.add(Resource.newResource(file).getFile());
54 }
55
56 public void addFile(File file)
57 {
58 _files.add(file);
59 }
60
61 public void addFiles(Collection<File> files)
62 {
63 _files.addAll(files);
64 }
65
66 public void removeFile(String file) throws IOException
67 {
68 _files.remove(Resource.newResource(file).getFile());
69 }
70
71 public void removeFile(File file)
72 {
73 _files.remove(file);
74 }
75
76 public void destroy()
77 {
78 for (File file : _files)
79 {
80 if (file.exists())
81 {
82 LOG.debug("Destroy {}",file);
83 IO.delete(file);
84 }
85 }
86 }
87
88 }