13bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar/* 23bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * Copyright (C) 2015 The Android Open Source Project 33bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License"); 43bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * you may not use this file except in compliance with the License. 53bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * You may obtain a copy of the License at 63bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * http://www.apache.org/licenses/LICENSE-2.0 73bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * Unless required by applicable law or agreed to in writing, software 83bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS, 93bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 103bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * See the License for the specific language governing permissions and 113bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar * limitations under the License. 123bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar */ 133bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar 14fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountpackage android.databinding.tool.writer; 15a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar 16a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyarimport org.apache.commons.io.FileUtils; 17a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar 18fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport android.databinding.tool.util.L; 19fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount 20a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyarimport java.io.File; 21a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyarimport java.io.IOException; 22a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar 23a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyarpublic abstract class JavaFileWriter { 24a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar public abstract void writeToFile(String canonicalName, String contents); 25a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar public void writeToFile(File exactPath, String contents) { 26a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar File parent = exactPath.getParentFile(); 27a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar parent.mkdirs(); 28a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar try { 29a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar L.d("writing file %s", exactPath.getAbsoluteFile()); 30a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar FileUtils.writeStringToFile(exactPath, contents); 31a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar } catch (IOException e) { 32a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar L.e(e, "Could not write to %s", exactPath); 33a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar } 34a6e4583962e19e8e93b4ca3f9fe3d34560b6d96cYigit Boyar } 353bd87eef217d80a233677d7e267224d0ed3c2c55Yigit Boyar} 36