• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.documentsui.archives;
18 
19 import android.net.Uri;
20 
21 public class ArchiveId {
22     private final static char DELIMITER = '#';
23 
24     public final Uri mArchiveUri;
25     public final int mAccessMode;
26     public final String mPath;
27 
ArchiveId(Uri archiveUri, int accessMode, String path)28     public ArchiveId(Uri archiveUri, int accessMode, String path) {
29         assert(archiveUri.toString().indexOf(DELIMITER) == -1);
30         assert(!path.isEmpty());
31 
32         mArchiveUri = archiveUri;
33         mAccessMode = accessMode;
34         mPath = path;
35     }
36 
fromDocumentId(String documentId)37     static public ArchiveId fromDocumentId(String documentId) {
38         final int delimiterPosition = documentId.indexOf(DELIMITER);
39         assert(delimiterPosition != -1);
40 
41         final int secondDelimiterPosition = documentId.indexOf(DELIMITER, delimiterPosition + 1);
42         assert(secondDelimiterPosition != -1);
43 
44         final String archiveUriPart = documentId.substring(0, delimiterPosition);
45         final String accessModePart = documentId.substring(delimiterPosition + 1,
46                 secondDelimiterPosition);
47 
48         final String pathPart = documentId.substring(secondDelimiterPosition + 1);
49 
50         return new ArchiveId(Uri.parse(archiveUriPart), Integer.parseInt(accessModePart),
51                 pathPart);
52     }
53 
toDocumentId()54     public String toDocumentId() {
55         return mArchiveUri.toString() + DELIMITER + mAccessMode + DELIMITER + mPath;
56     }
57 };
58