1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.xsdc; 18 19 import java.io.File; 20 import java.io.IOException; 21 import java.io.PrintWriter; 22 import java.io.StringWriter; 23 import java.util.Map; 24 25 public class FileSystem { 26 private File rootDirectory; 27 private Map<String, StringBuffer> fileOutputMap; 28 FileSystem(File rootDirectory)29 public FileSystem(File rootDirectory) { 30 this.rootDirectory = rootDirectory; 31 } 32 FileSystem(Map<String, StringBuffer> fileOutputMap)33 public FileSystem(Map<String, StringBuffer> fileOutputMap) { 34 this.fileOutputMap = fileOutputMap; 35 } 36 getPrintWriter(String fileName)37 public PrintWriter getPrintWriter(String fileName) throws IOException { 38 if (rootDirectory != null) { 39 return new PrintWriter(new File(rootDirectory, fileName)); 40 } else { 41 StringWriter sw = new StringWriter(); 42 fileOutputMap.put(fileName, sw.getBuffer()); 43 return new PrintWriter(sw); 44 } 45 } 46 } 47