// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java
// public class BusInitException extends ResponseException {
// 
//     public BusInitException() {
//         super("BUS INIT... ERROR");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java
// public class MisunderstoodCommandException extends ResponseException {
// 
//     public MisunderstoodCommandException() {
//         super("?");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java
// public class NoDataException extends ResponseException {
// 
//     public NoDataException() {
//         super("NO DATA");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java
// public class ResponseException extends RuntimeException {
// 
//     private String message;
// 
//     private String response;
// 
//     private String command;
// 
//     private boolean matchRegex;
// 
//     /**
//      * @param message a {@link java.lang.String} object.
//      */
//     protected ResponseException(String message) {
//         this.message = message;
//     }
// 
//     protected ResponseException(String message, boolean matchRegex) {
//         this.message = message;
//         this.matchRegex = matchRegex;
//     }
// 
//     private static String clean(String s) {
//         return s == null ? "" : s.replaceAll("\\s", "").toUpperCase();
//     }
// 
//     /**
//      * @param response a {@link java.lang.String} object.
//      * @return a boolean.
//      */
//     public boolean isError(String response) {
//         this.response = response;
//         if (matchRegex) {
//             return clean(response).matches(clean(message));
//         } else {
//             return clean(response).contains(clean(message));
//         }
//     }
// 
//     /**
//      * @param command a {@link java.lang.String} object.
//      */
//     public void setCommand(String command) {
//         this.command = command;
//     }
// 
//     @Override
//     public String getMessage() {
//         return "Error running " + command + ", response: " + response;
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java
// public class StoppedException extends ResponseException {
// 
//     public StoppedException() {
//         super("STOPPED");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java
// public class UnableToConnectException extends ResponseException {
// 
//     public UnableToConnectException() {
//         super("UNABLE TO CONNECT");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java
// public class UnknownErrorException extends ResponseException {
// 
//     public UnknownErrorException() {
//         super("ERROR");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java
// public class UnsupportedCommandException extends ResponseException {
// 
//     public UnsupportedCommandException() {
//         super("7F 0[0-9] 12", true);
//     }
// 
// }


import org.hexpresso.elm327.exceptions.BusInitException;
import org.hexpresso.elm327.exceptions.MisunderstoodCommandException;
import org.hexpresso.elm327.exceptions.NoDataException;
import org.hexpresso.elm327.exceptions.ResponseException;
import org.hexpresso.elm327.exceptions.StoppedException;
import org.hexpresso.elm327.exceptions.UnableToConnectException;
import org.hexpresso.elm327.exceptions.UnknownErrorException;
import org.hexpresso.elm327.exceptions.UnsupportedCommandException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

    /*
     * Imagine the following response 41 0c 00 0d.
     *
     * ELM sends strings!! So, ELM puts spaces between each "byte". And pay
     * attention to the fact that I've put the word byte in quotes, because 41
     * is actually TWO bytes (two chars) in the socket. So, we must do some more
     * processing..
     */
        String rawResponse = res.toString();
        rawResponse = rawResponse.replaceAll("SEARCHING", "");

        // TODO check this
        //rawResponse = rawResponse.replaceAll("(BUS INIT)|(BUSINIT)|(\\.)", "");

    /*
     * Data may have echo or informative text like "INIT BUS..." or similar.
     * The response ends with two carriage return characters. So we need to take
     * everything from the last carriage return before those two (trimmed above).
     */
        //kills multiline.. rawData = rawData.substring(rawData.lastIndexOf(13) + 1);
        //mResponse = mResponse.replaceAll("\\s", "");//removes all [ \t\n\x0B\f\r]

        // Generate the Response object
        mResponse.setRawResponse(rawResponse);
        if (mWithAutoProcessResponse) {
            mResponse.process();
        }
    }

    protected void checkForErrors() {

// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java
// public class BusInitException extends ResponseException {
// 
//     public BusInitException() {
//         super("BUS INIT... ERROR");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java
// public class MisunderstoodCommandException extends ResponseException {
// 
//     public MisunderstoodCommandException() {
//         super("?");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java
// public class NoDataException extends ResponseException {
// 
//     public NoDataException() {
//         super("NO DATA");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java
// public class ResponseException extends RuntimeException {
// 
//     private String message;
// 
//     private String response;
// 
//     private String command;
// 
//     private boolean matchRegex;
// 
//     /**
//      * @param message a {@link java.lang.String} object.
//      */
//     protected ResponseException(String message) {
//         this.message = message;
//     }
// 
//     protected ResponseException(String message, boolean matchRegex) {
//         this.message = message;
//         this.matchRegex = matchRegex;
//     }
// 
//     private static String clean(String s) {
//         return s == null ? "" : s.replaceAll("\\s", "").toUpperCase();
//     }
// 
//     /**
//      * @param response a {@link java.lang.String} object.
//      * @return a boolean.
//      */
//     public boolean isError(String response) {
//         this.response = response;
//         if (matchRegex) {
//             return clean(response).matches(clean(message));
//         } else {
//             return clean(response).contains(clean(message));
//         }
//     }
// 
//     /**
//      * @param command a {@link java.lang.String} object.
//      */
//     public void setCommand(String command) {
//         this.command = command;
//     }
// 
//     @Override
//     public String getMessage() {
//         return "Error running " + command + ", response: " + response;
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java
// public class StoppedException extends ResponseException {
// 
//     public StoppedException() {
//         super("STOPPED");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java
// public class UnableToConnectException extends ResponseException {
// 
//     public UnableToConnectException() {
//         super("UNABLE TO CONNECT");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java
// public class UnknownErrorException extends ResponseException {
// 
//     public UnknownErrorException() {
//         super("ERROR");
//     }
// 
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java
// public class UnsupportedCommandException extends ResponseException {
// 
//     public UnsupportedCommandException() {
//         super("7F 0[0-9] 12", true);
//     }
// 
// }


// Path: app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java
import org.hexpresso.elm327.exceptions.BusInitException;
import org.hexpresso.elm327.exceptions.MisunderstoodCommandException;
import org.hexpresso.elm327.exceptions.NoDataException;
import org.hexpresso.elm327.exceptions.ResponseException;
import org.hexpresso.elm327.exceptions.StoppedException;
import org.hexpresso.elm327.exceptions.UnableToConnectException;
import org.hexpresso.elm327.exceptions.UnknownErrorException;
import org.hexpresso.elm327.exceptions.UnsupportedCommandException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

    /*
     * Imagine the following response 41 0c 00 0d.
     *
     * ELM sends strings!! So, ELM puts spaces between each "byte". And pay
     * attention to the fact that I've put the word byte in quotes, because 41
     * is actually TWO bytes (two chars) in the socket. So, we must do some more
     * processing..
     */
        String rawResponse = res.toString();
        rawResponse = rawResponse.replaceAll("SEARCHING", "");

        // TODO check this
        //rawResponse = rawResponse.replaceAll("(BUS INIT)|(BUSINIT)|(\\.)", "");

    /*
     * Data may have echo or informative text like "INIT BUS..." or similar.
     * The response ends with two carriage return characters. So we need to take
     * everything from the last carriage return before those two (trimmed above).
     */
        //kills multiline.. rawData = rawData.substring(rawData.lastIndexOf(13) + 1);
        //mResponse = mResponse.replaceAll("\\s", "");//removes all [ \t\n\x0B\f\r]

        // Generate the Response object
        mResponse.setRawResponse(rawResponse);
        if (mWithAutoProcessResponse) {
            mResponse.process();
        }
    }

    protected void checkForErrors() {

        for (Class<? extends ResponseException> errorClass : ERROR_CLASSES) {
