OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2014, the Dart project authors. |
| 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. |
| 13 */ |
| 14 |
| 15 package com.google.dart.engine.internal.index.file; |
| 16 |
| 17 import java.io.BufferedInputStream; |
| 18 import java.io.BufferedOutputStream; |
| 19 import java.io.File; |
| 20 import java.io.FileInputStream; |
| 21 import java.io.FileOutputStream; |
| 22 import java.io.InputStream; |
| 23 import java.io.OutputStream; |
| 24 |
| 25 public class TemporaryFileManager implements FileManager { |
| 26 // private final File base = new File("/Users/scheglov/tmp/index"); |
| 27 private final File base; |
| 28 |
| 29 public TemporaryFileManager(File base) { |
| 30 this.base = base; |
| 31 clear(); |
| 32 } |
| 33 |
| 34 @Override |
| 35 public void clear() { |
| 36 File[] files = base.listFiles(); |
| 37 if (files != null) { |
| 38 for (File file : files) { |
| 39 file.delete(); |
| 40 } |
| 41 } |
| 42 } |
| 43 |
| 44 @Override |
| 45 public void delete(String name) { |
| 46 new File(base, name).delete(); |
| 47 } |
| 48 |
| 49 @Override |
| 50 public InputStream openInputStream(String name) throws Exception { |
| 51 File file = getFile(name); |
| 52 if (!file.isFile()) { |
| 53 return null; |
| 54 } |
| 55 InputStream stream = new FileInputStream(file); |
| 56 return new BufferedInputStream(stream); |
| 57 } |
| 58 |
| 59 @Override |
| 60 public OutputStream openOutputStream(String name) throws Exception { |
| 61 File file = getFile(name); |
| 62 OutputStream stream = new FileOutputStream(file); |
| 63 return new BufferedOutputStream(stream); |
| 64 } |
| 65 |
| 66 private File getFile(String name) { |
| 67 return new File(base, name); |
| 68 } |
| 69 } |
OLD | NEW |