Debian Codegraph @

brut.apktool/apktool-lib/src/main/java/brut/androlib/meta/MetaInfo.java

raw
1 /*
2 * Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
3 * Copyright (C) 2010 Connor Tumbleson <[email protected]>
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package brut.androlib.meta;
18
19 import org.yaml.snakeyaml.DumperOptions;
20 import org.yaml.snakeyaml.Yaml;
21 import org.yaml.snakeyaml.introspector.PropertyUtils;
22
23 import java.io.*;
24 import java.nio.charset.StandardCharsets;
25 import java.util.Collection;
26 import java.util.Map;
27
28 public class MetaInfo {
29 public String version;
30 public String apkFileName;
31 public boolean isFrameworkApk;
32 public UsesFramework usesFramework;
33 public Map<String, String> sdkInfo;
34 public PackageInfo packageInfo;
35 public VersionInfo versionInfo;
36 public boolean compressionType;
37 public boolean sharedLibrary;
38 public boolean sparseResources;
39 public Map<String, String> unknownFiles;
40 public Collection<String> doNotCompress;
41
42 private static Yaml getYaml() {
43 DumperOptions options = new DumperOptions();
44 options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
45
46 EscapedStringRepresenter representer = new EscapedStringRepresenter();
47 PropertyUtils propertyUtils = representer.getPropertyUtils();
48 propertyUtils.setSkipMissingProperties(true);
49
50 return new Yaml(new ClassSafeConstructor(), representer, options);
51 }
52
53 public void save(Writer output) {
54 DumperOptions options = new DumperOptions();
55 options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
56 getYaml().dump(this, output);
57 }
58
59 public void save(File file) throws IOException {
60 try(
61 FileOutputStream fos = new FileOutputStream(file);
62 OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
63 Writer writer = new BufferedWriter(outputStreamWriter)
64 ) {
65 save(writer);
66 }
67 }
68
69 public static MetaInfo load(InputStream is) {
70 return getYaml().loadAs(is, MetaInfo.class);
71 }
72 }