Example usage for java.io BufferedReader toString

List of usage examples for java.io BufferedReader toString

Introduction

In this page you can find the example usage for java.io BufferedReader toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:IoTatWork.NotifyResolutionManager.java

/**
 * //from   ww  w  .j  av  a2s .c  o m
 * @param notification
 * @return
 */
private boolean sendNotification(PendingResolutionNotification notification) {
    String xmlString = notification.toXML();

    String revocationPut = notification.getNotificationUrl() + notification.getRevocationHash();
    System.out.println("\nProcessing notification: " + revocationPut + "\n" + notification.toXML());
    // TODO logEvent
    //IoTatWorkApplication.logger.info("Sending pending resolution notification: "+revocationPut);
    IoTatWorkApplication.logger.info(LogMessage.SEND_RESOLUTION_NOTIFICATION + revocationPut);

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPut putRequest = new HttpPut(revocationPut);

    try {
        StringEntity input = new StringEntity(xmlString);

        input.setContentType("application/xml");
        putRequest.setEntity(input);

        HttpResponse response = httpClient.execute(putRequest);

        int statusCode = response.getStatusLine().getStatusCode();

        switch (statusCode) {
        case 200:
            IoTatWorkApplication.logger.info(LogMessage.RESOLUTION_NOTIFICATION_RESPONSE_STATUSCODE_200);
            break;
        case 400:
            BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
            String output = br.toString();
            /*
            while ((output = br.readLine()) != null) {
               System.out.println(output);
            }
            */
            JsonParser parser = new JsonParser();
            JsonObject jsonObj = (JsonObject) parser.parse(output);
            String code = jsonObj.get(JSON_PROCESSING_STATUS_CODE).getAsString();

            if (code.equals("NPR400")) {
                IoTatWorkApplication.logger.info(LogMessage.RESOLUTION_NOTIFICATION_RESPONSE_STATUSCODE_400);
            } else if (code.equals("NPR450")) {
                IoTatWorkApplication.logger.info(LogMessage.RESOLUTION_NOTIFICATION_RESPONSE_STATUSCODE_450);
            } else if (code.equals("NPR451")) {
                IoTatWorkApplication.logger.info(LogMessage.RESOLUTION_NOTIFICATION_RESPONSE_STATUSCODE_451);
            }

            break;
        case 404:
            IoTatWorkApplication.logger.info(LogMessage.RESOLUTION_NOTIFICATION_RESPONSE_STATUSCODE_404);
            break;
        case 500:
            IoTatWorkApplication.logger.info(LogMessage.RESOLUTION_NOTIFICATION_RESPONSE_STATUSCODE_500);
            break;
        default:
            break;
        }

        httpClient.getConnectionManager().shutdown();

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return true;

}

From source file:org.trianacode.taskgraph.util.FileUtils.java

/**
 * This function splits the next line createTool from the specified BufferReader into a vector of Strings contained
 * within the line. Each string is split up if they are separated by a single white space. The function returns a
 * StringVector which is basically, a Vector which only stores strings, so we don't have type-cast all the time.
 *///from ww  w. j av  a  2 s.c o m
public static Vector<String> readAndSplitLine(BufferedReader br) {
    if (br == null) {
        return null;
    }

    String line;

    try {
        line = br.readLine();
    } catch (IOException ee) {
        System.out.println("Couldn't input from " + br.toString());
        return null;
    }

    if (line == null) {
        return null;
    }

    return splitLine(line);
}

From source file:org.trianacode.taskgraph.util.FileUtils.java

/**
 * Reads all the file pointed to by the given reader into the returned string.  This function also closes the file
 * (since we have createTool it all!). </p> <p> For example, to open, createTool all, and close a file you type :-
 * </p>//from   ww  w .  j a  v  a 2  s .c  o  m
 * <pre>
 * String template = FileUtils.readFile(FileUtils.createReader(fileName));
 * </pre>
 */
public static String readFile(BufferedReader br) {
    String line;
    String str = "";

    if (br == null) {
        return str;
    }

    try {
        while ((line = br.readLine()) != null) {
            str = str + line + "\n";
        }
    } catch (IOException ee) {
        System.out.println("Couldn't input from " + br.toString());
        return null;
    }

    closeReader(br);

    return str;
}

From source file:com.example.kjpark.smartclass.NoticeTab.java

private void setSignatureLayout() {
    LayoutInflater dialogInflater = (LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    dialogView = dialogInflater.inflate(R.layout.dialog_signature, null);
    mSignaturePad = (SignaturePad) dialogView.findViewById(R.id.signature_pad);

    clearButton = (Button) dialogView.findViewById(R.id.clearButton);
    sendButton = (Button) dialogView.findViewById(R.id.sendButton);

    mSignaturePad.setOnSignedListener(new SignaturePad.OnSignedListener() {
        @Override//from w  w w.j  a v a  2 s  . c  om
        public void onSigned() {
            clearButton.setEnabled(true);
            sendButton.setEnabled(true);
        }

        @Override
        public void onClear() {
            clearButton.setEnabled(false);
            sendButton.setEnabled(false);
        }
    });
    clearButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSignaturePad.clear();
        }
    });
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //send sign image to server
            ConnectServer.getInstance().setAsncTask(new AsyncTask<String, Void, Boolean>() {
                Bitmap signatureBitmap = mSignaturePad.getSignatureBitmap();
                private String num = Integer.toString(currentViewItem);

                @Override
                protected Boolean doInBackground(String... params) {
                    URL obj = null;
                    try {
                        obj = new URL("http://165.194.104.22:5000/enroll_sign");
                        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

                        //implement below code if token is send to server
                        con = ConnectServer.getInstance().setHeader(con);

                        con.setDoOutput(true);

                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        signatureBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                        byte[] b = baos.toByteArray();
                        String sign_image = Base64.encodeToString(b, Base64.DEFAULT);
                        Log.d(TAG, "sign_image: " + sign_image.length());

                        String parameter = URLEncoder.encode("num", "UTF-8") + "="
                                + URLEncoder.encode(num, "UTF-8");
                        parameter += "&" + URLEncoder.encode("sign_image", "UTF-8") + "="
                                + URLEncoder.encode(sign_image, "UTF-8");

                        OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
                        wr.write(parameter);
                        wr.flush();

                        BufferedReader rd = null;

                        if (con.getResponseCode() == 200) {
                            // ? 
                            rd = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));

                            Log.d("---- success ----", rd.toString());

                        } else {
                            // ? 
                            rd = new BufferedReader(new InputStreamReader(con.getErrorStream(), "UTF-8"));
                            Log.d("---- failed ----", String.valueOf(rd.readLine()));
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Boolean aBoolean) {

                }
            });
            ConnectServer.getInstance().execute();
            signature_dialog.dismiss();
            loadBoards();
        }
    });
}

From source file:org.trianacode.taskgraph.util.FileUtils.java

/**
 * This function splits the file into a vector of Strings, each item in the vector representing one line. Used for
 * loading in the TrianaType file and useful for splitting up file into a vector of easily accessable lines. This
 * function also closes the file (since we have createTool it all!)
 *///from w ww.java2s.  c  o m
public static Vector<String> readAndSplitFile(BufferedReader br) {
    Vector<String> lines = new Vector<String>(10); // 10 should be OK

    if (br == null) {
        return null;
    }

    String line;

    try {
        while ((line = br.readLine()) != null) {
            lines.addElement(line);
        }
    } catch (IOException ee) {
        System.out.println("Couldn't input from " + br.toString());
        return null;
    }

    closeReader(br);

    return lines;
}

From source file:org.openiam.spml2.spi.example.ShellConnectorImpl.java

public ModifyResponseType modify(ModifyRequestType reqType) {
    String userName = null;/*from  w  w  w .j  a v a2  s. c  om*/
    String firstName = null;
    String lastName = null;
    String init = null;
    String displayName = null;
    String ou = null;
    String role = null;
    boolean change = false;
    String title = null;
    String userState = null;
    String sAMAccountName = null;

    String requestID = reqType.getRequestID();
    /* PSO - Provisioning Service Object -
     *     -  ID must uniquely specify an object on the target or in the target's namespace  
     *     -  Try to make the PSO ID immutable so that there is consistency across changes. */
    PSOIdentifierType psoID = reqType.getPsoID();
    userName = psoID.getID();

    /* targetID -  */
    String targetID = psoID.getTargetID();

    /* A) Use the targetID to look up the connection information under managed systems */
    ManagedSys managedSys = managedSysService.getManagedSys(targetID);
    ManagedSystemObjectMatch matchObj = null;
    List<ManagedSystemObjectMatch> matchObjList = managedSysObjectMatchDao.findBySystemId(targetID, "USER");
    if (matchObjList != null && matchObjList.size() > 0) {
        matchObj = matchObjList.get(0);
    }

    String host;
    String hostlogin;
    String hostpassword;

    host = managedSys.getHostUrl();
    hostlogin = managedSys.getUserId();
    hostpassword = managedSys.getDecryptPassword();

    // get the firstName and lastName values

    List<ModificationType> modTypeList = reqType.getModification();
    for (ModificationType mod : modTypeList) {
        ExtensibleType extType = mod.getData();
        List<ExtensibleObject> extobjectList = extType.getAny();
        for (ExtensibleObject obj : extobjectList) {
            System.out.println("Object:" + obj.getName() + " - operation=" + obj.getOperation());
            List<ExtensibleAttribute> attrList = obj.getAttributes();
            List<ModificationItem> modItemList = new ArrayList<ModificationItem>();
            for (ExtensibleAttribute att : attrList) {
                if (att.getOperation() != 0 && att.getName() != null) {
                    if (att.getName().equalsIgnoreCase("firstName")) {
                        firstName = att.getValue();
                        change = true;
                    }
                    if (att.getName().equalsIgnoreCase("lastName")) {
                        lastName = att.getValue();
                        change = true;
                    }
                    if (att.getName().equalsIgnoreCase("sAMAccountName")) {
                        sAMAccountName = att.getValue();
                        change = true;
                    }
                    if (att.getName().equalsIgnoreCase("displayName")) {

                        displayName = att.getValue();
                        change = true;
                    }
                    if (att.getName().equalsIgnoreCase("ou")) {
                        ou = att.getValue();
                        change = true;
                    }
                    if (att.getName().equalsIgnoreCase("role")) {
                        role = att.getValue();
                        change = true;
                    }
                    if (att.getName().equalsIgnoreCase("initials")) {
                        init = att.getValue();
                        change = true;
                    }
                    if (att.getName().equalsIgnoreCase("title")) {
                        title = att.getValue();
                        change = true;
                    }
                    if (att.getName().equalsIgnoreCase("userState")) {
                        userState = att.getValue();
                        change = true;
                    }

                }
            }
        }
    }

    StringBuffer strBuf = new StringBuffer();

    //   powershell -command "& c:\powershell\ad\Upd-AdUser.ps1 'cn=Raymond Collins,cn=Users,dc=iamdev,dc=local' 'Ray' 'Coly' 'P' 'Coly, Ray'  'Knight' 0"
    //   strBuf.append(" '"+ displayName +"' ");
    //   strBuf.append(" '"+ userName +"' ");

    strBuf.append("cmd /c powershell.exe -command \"& C:\\powershell\\ad\\Upd-AdUser.ps1 ");
    //strBuf.append("cmd /c notepad.exe ");user
    strBuf.append(" 'CN=" + userName + ",cn=USERS,DC=IAMDEV,DC=LOCAL' ");
    strBuf.append("'" + firstName + "' ");
    strBuf.append("'" + lastName + "' ");
    strBuf.append("'" + init + "' ");
    strBuf.append("'" + displayName + "' ");
    strBuf.append("'" + title + "' ");
    strBuf.append("" + userState + " \"");

    //strBuf.append(" '"+ ou +"' ");
    //strBuf.append(" '"+ title +"' \"");

    System.out.println("**Command line string= " + strBuf.toString());
    String[] cmdarray = { "cmd", strBuf.toString() };
    try {
        //Runtime.getRuntime().exec(cmdarray); //exec(strBuf.toString());
        Process p = Runtime.getRuntime().exec(strBuf.toString());
        System.out.println("Process =" + p);
        //OutputStream stream =  p.getOutputStream();
        //System.out.println( "stream=" + stream.toString() );

        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        System.out.println("stream reader=" + in.toString());
        in.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

    // assign to google 

    ModifyResponseType respType = new ModifyResponseType();
    respType.setStatus(StatusCodeType.SUCCESS);
    return respType;

}