1 /* 2 * Copyright (C) 2020 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.util; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 22 import org.xmlpull.v1.XmlSerializer; 23 24 import java.io.IOException; 25 26 /** 27 * Specialization of {@link XmlSerializer} which adds explicit methods to 28 * support consistent and efficient conversion of primitive data types. 29 * 30 * @hide 31 */ 32 public interface TypedXmlSerializer extends XmlSerializer { 33 /** 34 * Functionally equivalent to {@link #attribute(String, String, String)} but 35 * with the additional signal that the given value is a candidate for being 36 * canonicalized, similar to {@link String#intern()}. 37 */ attributeInterned(@ullable String namespace, @NonNull String name, @NonNull String value)38 @NonNull XmlSerializer attributeInterned(@Nullable String namespace, @NonNull String name, 39 @NonNull String value) throws IOException; 40 41 /** 42 * Encode the given strongly-typed value and serialize using 43 * {@link #attribute(String, String, String)}. 44 */ attributeBytesHex(@ullable String namespace, @NonNull String name, @NonNull byte[] value)45 @NonNull XmlSerializer attributeBytesHex(@Nullable String namespace, @NonNull String name, 46 @NonNull byte[] value) throws IOException; 47 48 /** 49 * Encode the given strongly-typed value and serialize using 50 * {@link #attribute(String, String, String)}. 51 */ attributeBytesBase64(@ullable String namespace, @NonNull String name, @NonNull byte[] value)52 @NonNull XmlSerializer attributeBytesBase64(@Nullable String namespace, @NonNull String name, 53 @NonNull byte[] value) throws IOException; 54 55 /** 56 * Encode the given strongly-typed value and serialize using 57 * {@link #attribute(String, String, String)}. 58 */ attributeInt(@ullable String namespace, @NonNull String name, int value)59 @NonNull XmlSerializer attributeInt(@Nullable String namespace, @NonNull String name, 60 int value) throws IOException; 61 62 /** 63 * Encode the given strongly-typed value and serialize using 64 * {@link #attribute(String, String, String)}. 65 */ attributeIntHex(@ullable String namespace, @NonNull String name, int value)66 @NonNull XmlSerializer attributeIntHex(@Nullable String namespace, @NonNull String name, 67 int value) throws IOException; 68 69 /** 70 * Encode the given strongly-typed value and serialize using 71 * {@link #attribute(String, String, String)}. 72 */ attributeLong(@ullable String namespace, @NonNull String name, long value)73 @NonNull XmlSerializer attributeLong(@Nullable String namespace, @NonNull String name, 74 long value) throws IOException; 75 76 /** 77 * Encode the given strongly-typed value and serialize using 78 * {@link #attribute(String, String, String)}. 79 */ attributeLongHex(@ullable String namespace, @NonNull String name, long value)80 @NonNull XmlSerializer attributeLongHex(@Nullable String namespace, @NonNull String name, 81 long value) throws IOException; 82 83 /** 84 * Encode the given strongly-typed value and serialize using 85 * {@link #attribute(String, String, String)}. 86 */ attributeFloat(@ullable String namespace, @NonNull String name, float value)87 @NonNull XmlSerializer attributeFloat(@Nullable String namespace, @NonNull String name, 88 float value) throws IOException; 89 90 /** 91 * Encode the given strongly-typed value and serialize using 92 * {@link #attribute(String, String, String)}. 93 */ attributeDouble(@ullable String namespace, @NonNull String name, double value)94 @NonNull XmlSerializer attributeDouble(@Nullable String namespace, @NonNull String name, 95 double value) throws IOException; 96 97 /** 98 * Encode the given strongly-typed value and serialize using 99 * {@link #attribute(String, String, String)}. 100 */ attributeBoolean(@ullable String namespace, @NonNull String name, boolean value)101 @NonNull XmlSerializer attributeBoolean(@Nullable String namespace, @NonNull String name, 102 boolean value) throws IOException; 103 } 104