Debian Codegraph @

core/java/android/os/PooledStringReader.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2015 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 android.os;
18
19 /**
20 * Helper class for reading pooling strings from a Parcel. It must be used
21 * in conjunction with {@link android.os.PooledStringWriter}. This really needs
22 * to be pushed in to Parcel itself, but doing that is... complicated.
23 * @hide
24 */
25 public class PooledStringReader {
26 private final Parcel mIn;
27
28 /**
29 * The pool of strings we have collected so far.
30 */
31 private final String[] mPool;
32
33 public PooledStringReader(Parcel in) {
34 mIn = in;
35 final int size = in.readInt();
36 mPool = new String[size];
37 }
38
39 public int getStringCount() {
40 return mPool.length;
41 }
42
43 public String readString() {
44 int idx = mIn.readInt();
45 if (idx >= 0) {
46 return mPool[idx];
47 } else {
48 idx = (-idx) - 1;
49 String str = mIn.readString();
50 mPool[idx] = str;
51 return str;
52 }
53 }
54 }