Example usage for java.lang String getBytes

List of usage examples for java.lang String getBytes

Introduction

In this page you can find the example usage for java.lang String getBytes.

Prototype

public byte[] getBytes() 

Source Link

Document

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

Usage

From source file:com.reversemind.glia.test.go3.java

public static void main(String... args) throws Exception {

    System.setProperty("http.proxyHost", "10.105.0.217");
    System.setProperty("http.proxyPort", "3128");

    System.setProperty("https.proxyHost", "10.105.0.217");
    System.setProperty("https.proxyPort", "3128");

    HttpHost proxy = new HttpHost("10.105.0.217", 3128);
    DefaultHttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    HttpGet request = new HttpGet(
            "https://twitter.com/i/profiles/show/splix/timeline/with_replies?include_available_features=1&include_entities=1&max_id=285605679744569344");
    HttpResponse response = client.execute(request);

    // Get the response
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));

    String sl = "";
    String line = "";
    while ((line = rd.readLine()) != null) {
        LOG.debug(line);//from  w  ww  .  j  a  v a 2 s  . co  m
        sl += line;
    }

    sl = new String(sl.getBytes(), "UTF-8");
    String sss = sl.replaceAll("\\{1,}", "\\").replaceAll("\\\"", "'").replaceAll("\\"", "'")
            .replaceAll("&gt;", ">").replaceAll("&lt;", "<").replaceAll("&amp;", "&").replaceAll("&apos;", "'")
            .replaceAll("\u003c", "<").replaceAll("\u003e", ">").replaceAll("\n", " ").replaceAll("\\/", "/")
            .replaceAll("\\'", "'");

    String sss2 = sss.replaceAll("\\'", "'");
    LOG.debug(sss);

    save("/opt/_del/go_sl.txt", sl);
    save("/opt/_del/go_sss.txt", sss);
    save("/opt/_del/go_line.txt", line);
    save("/opt/_del/go_sss2.txt", sss2);

    LOG.debug("\n\n\n\n\n");
    LOG.debug(sss);
    LOG.debug("\n\n\n\n\n");
    LOG.debug(URLDecoder.decode(sl, "UTF-8"));
    LOG.debug(URLDecoder.decode("\u0438\u043d\u043e\u0433\u0434\u0430", "UTF-8"));

    LOG.debug(URLDecoder.decode("\n            \u003c/span\u003e\n            \u003cb\u003e\n ", "UTF-8"));

}

From source file:com.sabre.devstudio.samples.dsApiCall.DSApiCalls.java

/**
 * @param args/*ww  w.j a v  a2  s.c  o m*/
 */
public static void main(String[] args) {

    // TODO Auto-generated method stub
    //
    //Request authentication
    //
    final String clientId = "";//Put Your Client Id Here
    final String clientSecret = "";//Put Your Secret Id Here

    //base64 encode clientId and clientSecret
    String encodedClientId = Base64.encodeBase64String((clientId).getBytes());
    String encodedClientSecret = Base64.encodeBase64String((clientSecret).getBytes());

    //Concatenate encoded client and secret strings, separated with colon
    String encodedClientIdSecret = encodedClientId + ":" + encodedClientSecret;

    //Convert the encoded concatenated string to a single base64 encoded string.
    encodedClientIdSecret = Base64.encodeBase64String(encodedClientIdSecret.getBytes());

    DSCommHandler dsC = new DSCommHandler();
    String token = dsC.getAuthToken("https://api.test.sabre.com", encodedClientIdSecret);
    String response = dsC.sendRequest("https://api.test.sabre.com/v1/shop/themes", token);
    //Display the response String
    System.out.println("SDS Response: " + response);

    //Other Example Calls
    //Call Destination Finder, for flights from Las Vegas and 5 day Length
    //String response2 = dsC.sendRequest("https://api.test.sabre.com/v1/shop/flights/fares?origin=LAS&lengthofstay=5", token);
    //Display the String
    //System.out.println("SDS Response: "+response2);

}

From source file:org.springside.examples.schedule.TransferOaDataToGx.java

public static void main(String[] args) {
    //      /*from  www  .  j  ava  2  s  .  co  m*/
    //      // ?
    //      HttpPost httpPost = new HttpPost("http://gxoa.cc/login!login.do?userName=&userPassword=gxuser&loginState=1");
    //      
    //      // ?connection poolclient
    //      RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20 * 1000)
    //            .setConnectTimeout(20 * 1000).build();
    //
    //      CloseableHttpClient  httpClient = HttpClientBuilder.create().setMaxConnTotal(20).setMaxConnPerRoute(20)
    //            .setDefaultRequestConfig(requestConfig).build();
    //      try {
    //         CloseableHttpResponse  closeableHttpResponse = httpClient.execute(httpPost);
    //         System.out.println(IOUtils.toString(closeableHttpResponse.getEntity().getContent(), "UTF-8"));
    //         HttpGet httpGet = new HttpGet("http://gxoa.cc/attachmentDownload.do?filePath=2010-07/2010-07-28-4bdd9279-c09e-4b68-80fc-c9d049c6bdfc-GXTC-1005124--??20091062.rar");
    //         CloseableHttpResponse closeableHttpResponseFile = httpClient.execute(httpGet);
    //         //FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\"));
    //         System.out.println(IOUtils.toString(closeableHttpResponseFile.getEntity().getContent(), "UTF-8"));
    //
    //         
    //      } catch (ClientProtocolException e) {
    //         // TODO Auto-generated catch block
    //         e.printStackTrace();
    //      } catch (IOException e) {
    //         // TODO Auto-generated catch block
    //         e.printStackTrace();
    //      }

    //      

    HttpPost httpPost = new HttpPost("http://219.239.33.123:9090/quickstart/api/getFileFromFTP");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();

    nvps.add(new BasicNameValuePair("filePath",
            "2015-04/2015-04-28-718f376f-b725-4e18-87e2-43e30124b2b5-GXTC-1506112-&-.rar"));

    String salt = "GXCX_OA_SALT";
    long currentTime = ((new Date().getTime() * 4 + 2) * 5 - 1) * 8 + 3;// by yucy
    String key = salt + currentTime;
    nvps.add(new BasicNameValuePair("key", Base64.encodeBase64String(key.getBytes())));

    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // ?connection poolclient
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20 * 1000)
            .setConnectTimeout(20 * 1000).build();
    CloseableHttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(20).setMaxConnPerRoute(20)
            .setDefaultRequestConfig(requestConfig).build();
    try {
        CloseableHttpResponse closeableHttpResponseFile = httpClient.execute(httpPost);

        FileUtils.writeByteArrayToFile(new File("D:/upload/templateBulletin.rar"),
                IOUtils.toByteArray(closeableHttpResponseFile.getEntity().getContent()));
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //TODO  ?
    //FileUtils.writeByteArrayToFile( file, FileUtils.readFileToByteArray( new File("D:/upload/templateBulletin.zip") ) );

}

From source file:com.hadoopvietnam.commons.crypt.J2MECrypto.java

public static void main(String[] args) {
    J2MECrypto crypto = new J2MECrypto("LetfyActionCrypto".getBytes());
    String code = System.currentTimeMillis() + " " + "tk1cntt@gmail.com" + " " + System.currentTimeMillis();
    String encode = new String(Base64.encodeBase64(crypto.encrypt((code).getBytes())));
    System.out.println(encode);/*from  ww  w  .j  a  v a2s .  com*/
    String decode = new String(crypto.decrypt(Base64.decodeBase64(encode.getBytes())));
    System.out.println(decode);
    System.out.println(DigestUtils.md5Hex(code));
}

From source file:com.manning.blogapps.chapter10.examples.AuthGet.java

public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        System.out.println("USAGE: authget <username> <password> <url>");
        System.exit(-1);/*from   ww  w.  ja v a 2s . co  m*/
    }
    String credentials = args[0] + ":" + args[1];
    String url = args[2];

    HttpClient httpClient = new HttpClient();
    GetMethod method = new GetMethod(url);
    method.setRequestHeader("Authorization",
            "Basic " + new String(Base64.encodeBase64(credentials.getBytes())));

    httpClient.executeMethod(method);
    System.out.println(method.getResponseBodyAsString());
}

From source file:com.manning.blogapps.chapter10.examples.AuthDelete.java

public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        System.out.println("USAGE: authdelete <username> <password> <url>");
        System.exit(-1);//from  w w w . ja v  a  2  s  .c  o m
    }
    String credentials = args[0] + ":" + args[1];
    String url = args[2];

    HttpClient httpClient = new HttpClient();
    DeleteMethod method = new DeleteMethod(url);
    method.setRequestHeader("Authorization",
            "Basic " + new String(Base64.encodeBase64(credentials.getBytes())));

    httpClient.executeMethod(method);
    System.out.println("Server returned status code: ");
}

From source file:cz.muni.fi.pa165.rentalofconstructionmachinery.restclient.App.java

public static int main(String[] args) {

    infoLogger.info("\n\nREST Sample Client\n\n");

    HttpHeaders httpHeaders = new HttpHeaders();
    String auth = REST_USERNAME + ":" + REST_PASSWORD;
    byte[] encodedAuthorisation = Base64.encode(auth.getBytes());
    httpHeaders.add("Authorization", "Basic " + new String(encodedAuthorisation));

    CustomerRestController.setHttpHeaders(httpHeaders);
    MachineRestController.setHttpHeaders(httpHeaders);

    try {//from   w ww . j a  va  2 s  .com
        switch (System.getProperty(ACTION, "")) {
        case "list":
            listEntities();
            break;
        case "details":
            getDetails();
            break;
        case "create":
            createEntity();
            break;
        case "edit":
            editEntity();
            break;
        case "delete":
            deleteEntity();
            break;
        default:
            infoLogger.info("Please, see the usage guide for this client in the README file.");
        }
    } catch (Exception e) {
        errorLogger.error("Houston, we have a problem.", e);
        infoLogger.info("\n\n");
        infoLogger.info("Ooops.");
        return 1;
    }

    infoLogger.info("\n\n");
    infoLogger.info("The operation was successful.");
    return 0;
}

From source file:cool.pandora.modeller.GetContainerTest.java

public static void main(final String[] args) throws IOException {
    try {//from  w w w .  j a va  2  s  .c om
        final String resource = ModellerClient.doGetContainerResources(
                URI.create("http://localhost:8080/fcrepo/rest/collection/test/001/res"));
        final Model model = ModelFactory.createDefaultModel();
        model.read(new ByteArrayInputStream(resource.getBytes()), null, "TTL");
        final ArrayList<String> children = getChilden(model);
        model.write(System.out, "TTL");
        System.out.println(children);
    } catch (ModellerClientFailedException e) {
        System.out.println(getMessage(e));
    }
}

From source file:CompRcv.java

public static void main(String[] args) throws Exception {
    Socket sock = new Socket(args[0], Integer.parseInt(args[1]));
    GZIPOutputStream zip = new GZIPOutputStream(sock.getOutputStream());
    String line;
    BufferedReader bis = new BufferedReader(new FileReader(args[2]));
    while (true) {
        try {/*from w w  w  .ja v a  2  s . co  m*/
            line = bis.readLine();
            if (line == null)
                break;
            line = line + "\n";
            zip.write(line.getBytes(), 0, line.length());
        } catch (Exception e) {
            break;
        }
    }
    zip.finish();
    zip.close();
    sock.close();
}

From source file:com.wolfsoftco.httpclient.RestClient.java

@SuppressWarnings("resource")
public static void main(String[] args) {
    CloseableHttpClient httpclient = null;
    CloseableHttpResponse response = null;
    try {/*from   w  w w.j a va2  s  . c o  m*/
        HttpEntity entity = null;
        String responseHtml = null;
        httpclient = HttpClients.custom().build();

        //Based on CURL line:
        //curl localhost:9090/oauth/token -d "grant_type=password&scope=write&username=greg&password=turnquist" -u foo:bar

        //clientid:secret
        String clientID = "foo:bar";

        HttpUriRequest login = RequestBuilder.post().setUri(new URI(URL))
                .addHeader("Authorization", "Basic " + Base64.encodeBase64String(clientID.getBytes()))
                .addParameter("grant_type", "password").addParameter("scope", "read")
                .addParameter("username", "greg").addParameter("password", "turnquist").build();

        response = httpclient.execute(login);
        entity = response.getEntity();

        responseHtml = EntityUtils.toString(entity);
        EntityUtils.consume(entity);

        JsonObject jsonObject = null;
        String token = null;
        if (responseHtml.startsWith("{")) {
            JsonParser parser = new JsonParser();
            jsonObject = parser.parse(responseHtml).getAsJsonObject();
            token = jsonObject.get("access_token").getAsString();
        }

        if (token != null) {
            HttpGet request = new HttpGet(URL_FLIGHTS);
            request.addHeader("Authorization", "Bearer " + token);

            response = httpclient.execute(request);
            entity = response.getEntity();
            responseHtml = EntityUtils.toString(entity);
            EntityUtils.consume(entity);
            System.out.println(responseHtml);

        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        try {

            if (httpclient != null)
                httpclient.close();
            if (response != null)
                response.close();

        } catch (IOException e) {
        }
    }
}