Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: dart/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/index/file/SeparateFileManager.java

Issue 371913004: Version 1.5.6 (Closed) Base URL: http://dart.googlecode.com/svn/branches/1.5/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 /**
26 * An implementation of {@link FileManager} that keeps each file in a separate f ile system file.
27 */
28 public class SeparateFileManager implements FileManager {
29 private final File base;
30
31 public SeparateFileManager(File base) {
32 this.base = base;
33 clear();
34 }
35
36 @Override
37 public void clear() {
38 File[] files = base.listFiles();
39 if (files != null) {
40 for (File file : files) {
41 file.delete();
42 }
43 }
44 }
45
46 @Override
47 public void delete(String name) {
48 getFile(name).delete();
49 }
50
51 @Override
52 public InputStream openInputStream(String name) throws Exception {
53 File file = getFile(name);
54 if (!file.isFile()) {
55 return null;
56 }
57 InputStream stream = new FileInputStream(file);
58 return new BufferedInputStream(stream);
59 }
60
61 @Override
62 public OutputStream openOutputStream(String name) throws Exception {
63 File file = getFile(name);
64 OutputStream stream = new FileOutputStream(file);
65 return new BufferedOutputStream(stream);
66 }
67
68 private File getFile(String name) {
69 return new File(base, name);
70 }
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698