1 /* 2 * Copyright (C) 2011 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.inputmethod.latin; 18 19 import java.io.File; 20 21 /** 22 * Immutable class to hold the address of an asset. 23 * As opposed to a normal file, an asset is usually represented as a contiguous byte array in 24 * the package file. Open it correctly thus requires the name of the package it is in, but 25 * also the offset in the file and the length of this data. This class encapsulates these three. 26 */ 27 public final class AssetFileAddress { 28 public final String mFilename; 29 public final long mOffset; 30 public final long mLength; 31 32 public AssetFileAddress(final String filename, final long offset, final long length) { 33 mFilename = filename; 34 mOffset = offset; 35 mLength = length; 36 } 37 38 public static AssetFileAddress makeFromFile(final File file) { 39 if (!file.isFile()) return null; 40 return new AssetFileAddress(file.getAbsolutePath(), 0L, file.length()); 41 } 42 43 public static AssetFileAddress makeFromFileName(final String filename) { 44 if (null == filename) return null; 45 return makeFromFile(new File(filename)); 46 } 47 48 public static AssetFileAddress makeFromFileNameAndOffset(final String filename, 49 final long offset, final long length) { 50 if (null == filename) return null; 51 final File f = new File(filename); 52 if (!f.isFile()) return null; 53 return new AssetFileAddress(filename, offset, length); 54 } 55 } 56