/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package buzzerproxy;

import java.io.DataOutputStream;
import java.util.HashMap;

/**
 *
 * @author Enger
 */
public class IO {

    IO() {
    }

    public boolean isIntNumber(String num) {
        try {
            Integer.parseInt(num);
        } catch (NumberFormatException nfe) {
            return false;
        }
        return true;
    } // public boolean isIntNumber(String num) {

    public String getFileExtension(String uri) {

        String extension = "";
        String[] uriFileTyp = uri.split("\\.");
        extension = uriFileTyp[uriFileTyp.length - 1];

        return extension;

    } // public String getFileExtension(String uri){

    public boolean isValidFileTyp(String uri, String filetyp) {

        boolean is = false;
        boolean in = false;

        String[] content = filetyp.split("\\+");
        String[] uriFileTyp = uri.split("\\.");

        for (int i = 0; i < content.length; i++) {
//System.out.println("urifiletyp: "+uriFileTyp[uriFileTyp.length - 1] + " und " + content[i]);
            if (uriFileTyp[uriFileTyp.length - 1].contains(content[i].replaceFirst("\\.", ""))) {
                is = true;
                //     System.out.println(uri + " und filetype: " + content[i] + "  sind gleich");
            } else {
                //   System.out.println(uri + " und filetype: " + content[i] + "  sind NICHT gleich");
            }// if ( uri.endsWith(content[i])){
        } //  for ( int i=0;i<content.length;i++){
        return is;

    } //  public boolean isValidFileTyp(String uri, String filetyp){

    public boolean isSet(DataOutputStream str) {

        boolean status = false;
        try {
            if (str == null || !(str instanceof DataOutputStream) || str.size() <= 0) {
                status = false;
            } else {
                status = true;
            } // if ( str == null || !(str instanceof String)){
        } catch (NullPointerException e) {
            status = false;
        } catch (Exception e) {
            status = false;
        }
        return status;

    } //public boolean isSet(DataOutputStream str){

    public boolean isSet(HashMap str) {

        boolean status = false;
        try {
            if (str == null || !(str instanceof HashMap) || str.size() <= 0) {
                status = false;
            } else {
                status = true;
            } // if ( str == null || !(str instanceof String)){
        } catch (NullPointerException e) {
            status = false;
        } catch (Exception e) {
            status = false;
        }
        return status;

    } // public boolean isSet(HashMap str){

    public boolean isSet(String str) {

        boolean status = false;
        try {
            if (str == null || !(str instanceof String) || str.isEmpty() || str.equalsIgnoreCase("")) {
                status = false;
            } else {
                status = true;
            } // if ( str == null || !(str instanceof String)){
        } catch (NullPointerException e) {
            status = false;
        } catch (Exception e) {
            status = false;
        }
        return status;

    } // public boolean isSet(String str){
} // public class IO {
//
//public boolean isValidFileTyp(String uri, String filetyp) {
//
//        boolean is = false;
//        boolean in = false;
//        ArrayList<String> l = new ArrayList<String>();
//
//        String[] content = filetyp.split("");
//        String fT = "";
//        for (int i = 0; i < content.length; i++) {
//            if (in) {
//                fT += content[i];
//            }
//            if (content[i].equals("\\.")) {
//                in = true;
//            }
//            if (content[i].equals("\\|")) {
//                in = false;
//                fT = "";
//                l.add(fT);
//            }
//        } // for (int i = 0; i < content.length; i++) {
//
//        String[] uriFileTyp = uri.split("\\.");
//        System.out.println("urifiletyp: "+uriFileTyp[uriFileTyp.length - 1]);
//
//        for ( String ftyp : l){
//           System.out.println("FileTyp: "+ftyp);
//        }
////        for (int i = 0; i < content.length; i++) {
////
////            if (uriFileTyp[uriFileTyp.length - 1].endsWith(content[i]) && !content[i].isEmpty()) {
////                is = true;
////                System.out.println(uri + " und filetype: " + content[i] + "  sind gleich");
////            } else {
////                System.out.println(uri + " und filetype: " + content[i] + "  sind NICHT gleich");
////            }// if ( uri.endsWith(content[i])){
////        } //  for ( int i=0;i<content.length;i++){
//        return is;
//
//    } //  public boolean isValidFileTyp(String uri, String filetyp){