package se.vidstige.jadb.managers;

import se.vidstige.jadb.JadbDevice;
import se.vidstige.jadb.JadbException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * A class which works with properties, uses getprop and setprop methods of android shell
 */
public class PropertyManager {
    private final Pattern pattern = Pattern.compile("^\\[([a-zA-Z0-9_.-]*)\\]:.\\[([^\\[\\]]*)\\]");
    private final JadbDevice device;

    public PropertyManager(JadbDevice device) {
        this.device = device;
    }

    public Map<String, String> getprop() throws IOException, JadbException {
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(device.executeShell("getprop")));
            return parseProp(bufferedReader);
        } finally {
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        }
    }

    private Map<String, String> parseProp(BufferedReader bufferedReader) throws IOException {
        HashMap<String, String> result = new HashMap<>();

        String line;
        Matcher matcher = pattern.matcher("");

        while ((line = bufferedReader.readLine()) != null) {
            matcher.reset(line);

            if (matcher.find()) {
                if (matcher.groupCount() < 2) {
                    System.err.println("Property line: " + line + " does not match patter. Ignoring");
                    continue;
                }
                String key = matcher.group(1);
                String value = matcher.group(2);
                result.put(key, value);
            }
        }

        return result;
    }
}

@@ -749,16 +749,21 @@
         
+try (
 Buffered
@@ -789,14 +789,8 @@
 er =
- null;
 %0A   
@@ -798,14 +798,9 @@
     
-try %7B%0A
+ 
     
@@ -806,33 +806,16 @@
         
- bufferedReader =
  new Buf
@@ -880,17 +880,19 @@
 prop%22)))
-;
+) %7B
 %0A       
@@ -934,124 +934,8 @@
 r);%0A
-        %7D finally %7B%0A            if (bufferedReader != null) %7B%0A                bufferedReader.close();%0A            %7D%0A
     

Use try-with-resources to close PropertyManager's reader