2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.documentsui.model;
19 import com.android.documentsui.RootsCache;
21 import java.io.DataInputStream;
22 import java.io.DataOutputStream;
23 import java.io.IOException;
24 import java.net.ProtocolException;
25 import java.util.LinkedList;
28 * Representation of a stack of {@link DocumentInfo}, usually the result of a
29 * user-driven traversal.
31 public class DocumentStack extends LinkedList<DocumentInfo> implements Durable {
32 private static final int VERSION_INIT = 1;
34 public RootInfo getRoot(RootsCache roots) {
35 return roots.findRoot(getLast().uri);
38 public String getTitle(RootsCache roots) {
40 return getRoot(roots).title;
41 } else if (size() > 1) {
42 return peek().displayName;
54 public void read(DataInputStream in) throws IOException {
55 final int version = in.readInt();
58 final int size = in.readInt();
59 for (int i = 0; i < size; i++) {
60 final DocumentInfo doc = new DocumentInfo();
66 throw new ProtocolException("Unknown version " + version);
71 public void write(DataOutputStream out) throws IOException {
72 out.writeInt(VERSION_INIT);
73 final int size = size();
75 for (int i = 0; i < size; i++) {
76 final DocumentInfo doc = get(i);