1 /* 2 * Copyright (C) 2012 The Libphonenumber Authors 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.google.i18n.phonenumbers.buildtools; 18 19 import java.io.Closeable; 20 import java.io.File; 21 import java.io.IOException; 22 import java.util.logging.Level; 23 import java.util.logging.Logger; 24 25 /** 26 * Abstracts the way GeneratePhonePrefixDataEntryPoint creates files and writes 27 * the phone prefix data to them. 28 */ 29 public abstract class AbstractPhonePrefixDataIOHandler { 30 private static final Logger logger = Logger.getLogger( 31 AbstractPhonePrefixDataIOHandler.class.getName()); 32 /** 33 * Adds the provided file to a global output that can be for example a JAR. 34 * 35 * @throws IOException 36 */ addFileToOutput(File file)37 abstract void addFileToOutput(File file) throws IOException; 38 39 /** 40 * Creates a new file from the provided path. 41 */ createFile(String path)42 abstract File createFile(String path); 43 44 /** 45 * Releases the resources used by the underlying implementation if any. 46 */ close()47 abstract void close(); 48 49 /** 50 * Closes the provided file and logs any potential IOException. 51 */ closeFile(Closeable closeable)52 void closeFile(Closeable closeable) { 53 if (closeable == null) { 54 return; 55 } 56 try { 57 closeable.close(); 58 } catch (IOException e) { 59 logger.log(Level.WARNING, e.getMessage()); 60 } 61 } 62 } 63