• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * 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 class AssetFileAddress {
28     public final String mFilename;
29     public final long mOffset;
30     public final long mLength;
31 
AssetFileAddress(final String filename, final long offset, final long length)32     public AssetFileAddress(final String filename, final long offset, final long length) {
33         mFilename = filename;
34         mOffset = offset;
35         mLength = length;
36     }
37 
makeFromFileName(final String filename)38     public static AssetFileAddress makeFromFileName(final String filename) {
39         if (null == filename) return null;
40         final File f = new File(filename);
41         if (!f.isFile()) return null;
42         return new AssetFileAddress(filename, 0l, f.length());
43     }
44 
makeFromFileNameAndOffset(final String filename, final long offset, final long length)45     public static AssetFileAddress makeFromFileNameAndOffset(final String filename,
46             final long offset, final long length) {
47         if (null == filename) return null;
48         final File f = new File(filename);
49         if (!f.isFile()) return null;
50         return new AssetFileAddress(filename, offset, length);
51     }
52 }
53