1/*
2 * Copyright (C) 2012 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
17package libcore.io;
18
19public final class DropBox {
20
21    /**
22     * Hook for customizing how events are reported.
23     */
24    private static volatile Reporter REPORTER = new DefaultReporter();
25
26    /**
27     * Used to replace default Reporter for logging events. Must be non-null.
28     */
29    public static void setReporter(Reporter reporter) {
30        if (reporter == null) {
31            throw new NullPointerException("reporter == null");
32        }
33        REPORTER = reporter;
34    }
35
36    /**
37     * Returns non-null Reporter.
38     */
39    public static Reporter getReporter() {
40        return REPORTER;
41    }
42
43    /**
44     * Interface to allow customization of reporting behavior.
45     */
46    public static interface Reporter {
47        public void addData(String tag, byte[] data, int flags);
48        public void addText(String tag, String data);
49    }
50
51    /**
52     * Default Reporter which reports events to the log.
53     */
54    private static final class DefaultReporter implements Reporter {
55
56        public void addData(String tag, byte[] data, int flags) {
57            System.out.println(tag + ": " + Base64.encode(data));
58        }
59
60        public void addText(String tag, String data) {
61            System.out.println(tag + ": " + data);
62        }
63    }
64
65    public static void addData(String tag, byte[] data, int flags) {
66        getReporter().addData(tag, data, flags);
67    }
68
69    public static void addText(String tag, String data) {
70        getReporter().addText(tag, data);
71    }
72}
73