1 /* 2 * Copyright (C) 2010 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.dexgen.util; 18 19 import java.io.File; 20 21 /** 22 * Helper class used primarily for holding path on the device of different 23 * files arising in the dex class generation process. 24 */ 25 public class PathHolder { 26 27 public static final String DEX_FILE_EXTENSION = ".dex"; 28 29 public static final String JAR_FILE_EXTENSION = ".jar"; 30 31 /** {@code non-null;} directory location of the dex-related files */ 32 private final String dirLocation; 33 34 /** {@code non-null;} common file name prefix of the created files */ 35 private final String fileNamePrefix; 36 37 /** 38 * Creates an instance of {@code PathHolder} initialized with the directory 39 * location for storage of temporary files and common file name prefix for these 40 * files. 41 * 42 * @param dirLocation {@code non-null;} path to directory used for storage of temporary files 43 * @param fileNamePrefix {@code non-null;} common file name prefix across all the temporary 44 * files involved in the dex class generation and loading process 45 */ PathHolder(String dirLocation, String fileNamePrefix)46 public PathHolder(String dirLocation, String fileNamePrefix) { 47 if (dirLocation == null) { 48 throw new NullPointerException("dirLocation == null"); 49 } 50 if (fileNamePrefix == null) { 51 throw new NullPointerException("fileNamePrefix == null"); 52 } 53 54 this.dirLocation = dirLocation; 55 this.fileNamePrefix = fileNamePrefix; 56 } 57 getFileName()58 public String getFileName() { 59 return fileNamePrefix; 60 } 61 getDexFilePath()62 public String getDexFilePath() { 63 return dirLocation + File.separator + fileNamePrefix + DEX_FILE_EXTENSION; 64 } 65 getDexFileName()66 public String getDexFileName() { 67 return fileNamePrefix + DEX_FILE_EXTENSION; 68 } 69 getJarFilePath()70 public String getJarFilePath() { 71 return dirLocation + File.separator + fileNamePrefix + JAR_FILE_EXTENSION; 72 } 73 getJarFileName()74 public String getJarFileName() { 75 return fileNamePrefix + JAR_FILE_EXTENSION; 76 } 77 getDirLocation()78 public String getDirLocation() { 79 return dirLocation; 80 } 81 } 82