• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
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 package com.google.android.libraries.mobiledatadownload.file.samples;
17 
18 import android.net.Uri;
19 import com.google.android.libraries.mobiledatadownload.file.backends.JavaFileBackend;
20 import com.google.android.libraries.mobiledatadownload.file.spi.Backend;
21 import com.google.android.libraries.mobiledatadownload.file.spi.ForwardingBackend;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 
26 /** An example backend that wraps another backend and a transform. Encodes all data as base64. */
27 public class Base64Backend extends ForwardingBackend {
28   private final Base64Transform base64 = new Base64Transform();
29   private final Backend javaBackend = new JavaFileBackend();
30 
31   @Override
delegate()32   protected Backend delegate() {
33     return javaBackend;
34   }
35 
36   @Override
name()37   public String name() {
38     return "base64";
39   }
40 
41   @Override
openForRead(Uri uri)42   public InputStream openForRead(Uri uri) throws IOException {
43     return base64.wrapForRead(uri, super.openForRead(uri));
44   }
45 
46   @Override
openForWrite(Uri uri)47   public OutputStream openForWrite(Uri uri) throws IOException {
48     return base64.wrapForWrite(uri, super.openForWrite(uri));
49   }
50 
51   @Override
openForAppend(Uri uri)52   public OutputStream openForAppend(Uri uri) throws IOException {
53     return base64.wrapForAppend(uri, super.openForAppend(uri));
54   }
55 }
56