blob: 631abddab06cc1e6280da35bc8e1fb6c4593cee4 [file] [log] [blame]
Adnan Begovicd5fdee92015-11-13 15:28:21 -08001/*
2 * Copyright (C) 2015 The CyanogenMod 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
17import java.io.BufferedReader;
18import java.io.FileReader;
19import java.io.IOException;
20import java.util.ArrayList;
21
22/**
23 * Created by adnan on 11/17/15.
24 */
25public class ReadCommand extends Command {
26 private String targetFile;
27 private ArrayList<Setting> targetList;
28 private String targetUri;
29
30 protected ReadCommand(String targetFile, String targetUri, ArrayList<Setting> targetList) {
31 this.targetFile = targetFile;
32 this.targetUri = targetUri;
33 this.targetList = targetList;
34 }
35
36 @Override
37 public void run() {
38 System.out.println("\nReading settings for authority "
39 + getAuthority() + " for target uri " + targetUri + " from file "
40 + targetFile +"...");
41 read(targetFile, targetUri, targetList);
42 synchronized (this) {
43 notifyAll();
44 }
45 }
46
47 private void read(String fileName, String uri, ArrayList<Setting> arrayList) {
48 try {
49 BufferedReader in = new BufferedReader(
50 new FileReader(fileName));
51 String line;
52 //Skip first two lines of header
53 for (int i = 0; i < 2; i++) {
54 in.readLine();
55 }
56 while ((line = in.readLine()) != null) {
57 if (!line.startsWith("Row: ")) {
58 throw new IOException("Unable to read settings");
59 }
60 if (MigrationTest.DEBUG) {
61 System.out.println("LINE: " + line);
62 }
63 Setting setting = RowParser.parseAndPopulate(false, line);
64 //Sanitize
65 if (filter(uri, setting)) {
66 continue;
67 }
68 arrayList.add(setting);
69 }
70 in.close();
71 } catch (IOException e) {
72 System.err.println("Error ");
73 e.printStackTrace();
74 }
75 }
76}