Example usage for java.lang Integer toString

List of usage examples for java.lang Integer toString

Introduction

In this page you can find the example usage for java.lang Integer toString.

Prototype

@HotSpotIntrinsicCandidate
public static String toString(int i) 

Source Link

Document

Returns a String object representing the specified integer.

Usage

From source file:Main.java

public static String executePost(String url, String parameters) throws IOException {

    URL request = new URL(url);
    HttpURLConnection connection = (HttpURLConnection) request.openConnection();
    connection.setDoOutput(true);/* w  w  w  .  j a va2  s .c  om*/
    connection.setDoInput(true);
    connection.setInstanceFollowRedirects(false);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("User-Agent", "StripeConnectAndroid");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("charset", "utf-8");
    connection.setRequestProperty("Content-Length", "" + Integer.toString(parameters.getBytes().length));
    connection.setUseCaches(false);

    DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
    wr.writeBytes(parameters);
    wr.flush();
    wr.close();

    String response = streamToString(connection.getInputStream());
    connection.disconnect();
    return response;

}

From source file:Main.java

/** convert bitrate To String*/
public static String bitrateToString(int nBitr) {

    String s;//from   w  w  w .j  a v a  2  s . c  o m
    nBitr /= 1024;
    if (nBitr < 1024) {
        s = Integer.toString(nBitr) + "k";
    } else {
        String str = Float.toString(nBitr / 1024.0f);
        int n = str.indexOf('.');
        if (n >= 0 && n < str.length() - 2)
            str = str.substring(0, n + 2);

        s = (str + "m");
    }
    return s;
}

From source file:Main.java

public static String executeHttpsPost(String url, String data, InputStream key) {
    HttpsURLConnection localHttpsURLConnection = null;
    try {//from  w w  w  .j a  va2s  .c  o m
        URL localURL = new URL(url);
        localHttpsURLConnection = (HttpsURLConnection) localURL.openConnection();
        localHttpsURLConnection.setRequestMethod("POST");
        localHttpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        localHttpsURLConnection.setRequestProperty("Content-Length",
                "" + Integer.toString(data.getBytes().length));
        localHttpsURLConnection.setRequestProperty("Content-Language", "en-US");

        localHttpsURLConnection.setUseCaches(false);
        localHttpsURLConnection.setDoInput(true);
        localHttpsURLConnection.setDoOutput(true);

        localHttpsURLConnection.connect();
        Certificate[] arrayOfCertificate = localHttpsURLConnection.getServerCertificates();

        byte[] arrayOfByte1 = new byte[294];
        DataInputStream localDataInputStream = new DataInputStream(key);
        localDataInputStream.readFully(arrayOfByte1);
        localDataInputStream.close();

        Certificate localCertificate = arrayOfCertificate[0];
        PublicKey localPublicKey = localCertificate.getPublicKey();
        byte[] arrayOfByte2 = localPublicKey.getEncoded();

        for (int i = 0; i < arrayOfByte2.length; i++) {
            if (arrayOfByte2[i] != arrayOfByte1[i])
                throw new RuntimeException("Public key mismatch");
        }

        DataOutputStream localDataOutputStream = new DataOutputStream(
                localHttpsURLConnection.getOutputStream());
        localDataOutputStream.writeBytes(data);
        localDataOutputStream.flush();
        localDataOutputStream.close();

        InputStream localInputStream = localHttpsURLConnection.getInputStream();
        BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localInputStream));

        StringBuffer localStringBuffer = new StringBuffer();
        String str1;
        while ((str1 = localBufferedReader.readLine()) != null) {
            localStringBuffer.append(str1);
            localStringBuffer.append('\r');
        }
        localBufferedReader.close();

        return localStringBuffer.toString();
    } catch (Exception localException) {
        byte[] arrayOfByte1;
        localException.printStackTrace();
        return null;
    } finally {
        if (localHttpsURLConnection != null)
            localHttpsURLConnection.disconnect();
    }
}

From source file:Main.java

/**
 * Replace pattern [SCILAB_FIGURE_ID] by the figure index
 * @param initialString string read in XML file
 * @param parentFigureId the figure ID// w w w  .  ja v  a  2  s.com
 * @return callback string
 */
private static String replaceFigureID(String initialString, Integer parentFigureId) {
    return initialString.replaceAll("\\[SCILAB_FIGURE_ID\\]", Integer.toString(parentFigureId));
}

From source file:Main.java

public static String toString(Collection<Integer> stack, String delimiterChars) {
    if (stack.isEmpty()) {
        return "";
    }//w w  w .  j  av a  2  s  .  co m
    if (stack.size() == 1) {
        return Integer.toString(stack.iterator().next());
    }
    StringWriter writer = new StringWriter();
    String delimiter = "";
    for (Integer item : stack) {
        writer.append(delimiter);
        writer.append(Integer.toString(item));
        delimiter = delimiterChars;
    }
    return writer.toString();
}

From source file:Main.java

static public void appendDateNode(Document owner, Element appendElement, String name, Date date) {
    Element dateElem = owner.createElement(name);
    appendElement.appendChild(dateElem);
    appendSingleValElement(owner, dateElem, "month", Integer.toString(date.getMonth() + 1));
    appendSingleValElement(owner, dateElem, "day", Integer.toString(date.getDate()));
    appendSingleValElement(owner, dateElem, "year", Integer.toString(date.getYear() + 1900));
    appendSingleValElement(owner, dateElem, "hour", Integer.toString(date.getHours()));
    appendSingleValElement(owner, dateElem, "minute", Integer.toString(date.getMinutes()));
    appendSingleValElement(owner, dateElem, "second", Integer.toString(date.getSeconds()));
}

From source file:Main.java

/**
 * Creates an element with content in the form of an integer
 *//*from  ww w  .  java  2  s .  co m*/
public static Element createElement(Element parent, Document document, String name, int value) {
    return createElement(parent, document, name, Integer.toString(value));
}

From source file:DBMS.UpdateFileUpload.java

public static boolean processFile(String path, FileItemStream item, int id) {
    try {/*from  ww w. j  av a2  s .  co m*/
        String check = item.getName();
        if (check.endsWith(".jpg") || check.endsWith(".JPG")) {
            String imstring = "images/" + Integer.toString(id);
            File f = new File(path + File.separator + imstring);
            if (!f.exists())
                f.mkdir();
            File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName());
            FileOutputStream fos = new FileOutputStream(savedFile);
            InputStream is = item.openStream();
            int x = 0;
            byte[] b = new byte[1024];
            while ((x = is.read(b)) != -1) {
                fos.write(b, 0, x);
            }
            fos.flush();
            fos.close();
            String dbimage = imstring + "/a.jpg";
            //dc.enterImage(dbimage);
            //im =dbimage;
            //System.out.println("Resizing!");
            //Resize rz = new Resize();
            //rz.resize(dbimage);
            BufferedImage originalImage = ImageIO.read(savedFile);
            int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
            BufferedImage resizeImageJpg = resizeImage(originalImage, type);
            ImageIO.write(resizeImageJpg, "jpg", savedFile);
            File rFile = new File(f.getAbsolutePath() + "/a.jpg");
            savedFile.renameTo(rFile);
            ProfileEditDB dc = new ProfileEditDB();
            dc.enterImage(id, dbimage);
            System.out.println("Link Entered to Database!");
            return true;
        }

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

From source file:Counter.java

public String toString() {
    return Integer.toString(i);
}

From source file:Main.java

public static PreparedStatement createFieldsInsert(Connection conn, int layerId, String name,
        String description, String fieldId, String fieldType, String sid, String sname, String sdesc,
        boolean indb, boolean enabled, boolean namesearch, boolean defaultlayer, boolean intersect,
        boolean layerbranch, boolean analysis, boolean addToMap) throws SQLException {
    // TOOD slightly different statement if sdesc is null...

    PreparedStatement stFieldsInsert = conn.prepareStatement(
            "INSERT INTO fields (name, id, \"desc\", type, spid, sid, sname, sdesc, indb, enabled, last_update, namesearch, defaultlayer, \"intersect\", layerbranch, analysis, addtomap)"
                    + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
    stFieldsInsert.setString(1, name);/*www  .  ja v a  2 s .co m*/
    stFieldsInsert.setString(2, fieldId);
    stFieldsInsert.setString(3, description);
    stFieldsInsert.setString(4, fieldType);
    stFieldsInsert.setString(5, Integer.toString(layerId));
    stFieldsInsert.setString(6, sid);
    stFieldsInsert.setString(7, sname);

    if (sdesc == null || sdesc.isEmpty()) {
        stFieldsInsert.setNull(8, Types.VARCHAR);
    } else {
        stFieldsInsert.setString(8, sdesc);
    }

    stFieldsInsert.setBoolean(9, indb);
    stFieldsInsert.setBoolean(10, enabled);
    stFieldsInsert.setTimestamp(11, new Timestamp(System.currentTimeMillis()));
    stFieldsInsert.setBoolean(12, namesearch);
    stFieldsInsert.setBoolean(13, defaultlayer);
    stFieldsInsert.setBoolean(14, intersect);
    stFieldsInsert.setBoolean(15, layerbranch);
    stFieldsInsert.setBoolean(16, analysis);
    stFieldsInsert.setBoolean(17, addToMap);

    return stFieldsInsert;
}