List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] argv) { byte[] bytes = new byte[] { 65, 66, 67, 68 }; try {/*from w ww .j ava2 s . c o m*/ System.out.println(new String(bytes, "ASCII")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) { byte[] bytes = new byte[] { 65, 66, 67, 68 }; try {/*from w w w . j a v a2s . c o m*/ System.out.println(new String(bytes, 1, 3, "ASCII")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:StringConverter.java
public static void main(String[] args) { System.out.println(System.getProperty("file.encoding")); String original = new String("A" + "\u00ea" + "\u00f1" + "\u00fc" + "C"); System.out.println("original = " + original); System.out.println();/*from w w w. j a va2 s . c om*/ try { byte[] utf8Bytes = original.getBytes("UTF8"); byte[] defaultBytes = original.getBytes(); String roundTrip = new String(utf8Bytes, "UTF8"); System.out.println("roundTrip = " + roundTrip); System.out.println(); printBytes(utf8Bytes, "utf8Bytes"); System.out.println(); printBytes(defaultBytes, "defaultBytes"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:org.eclipse.lyo.adapter.tdb.clients.OSLCTriplestoreAdapterResourceCreationClient.java
public static void main(String[] args) { String baseHTTPURI = "http://localhost:" + OSLC4JTDBApplication.portNumber + "/oslc4jtdb"; String projectId = "default"; // URI of the HTTP request String tdbResourceCreationFactoryURI = baseHTTPURI + "/services/" + projectId + "/resources"; // create RDF to add to the triplestore Model resourceRDFModel = ModelFactory.createDefaultModel(); Resource resource = ResourceFactory .createResource("http://localhost:8585/oslc4jtdb/services/default/resources/newBlock4"); Property property = ResourceFactory/* ww w . java 2s . c o m*/ .createProperty("http://localhost:8585/oslc4jtdb/services/default/resources/newProperty4"); RDFNode object = ResourceFactory .createResource("http://localhost:8585/oslc4jtdb/services/default/resources/newObject4"); resourceRDFModel.add(resource, property, object); StringWriter out = new StringWriter(); resourceRDFModel.write(out, "RDF/XML"); resourceRDFModel.write(System.out); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(tdbResourceCreationFactoryURI); String xml = out.toString(); HttpEntity entity; try { entity = new ByteArrayEntity(xml.getBytes("UTF-8")); post.setEntity(entity); post.setHeader("Accept", "application/rdf+xml"); HttpResponse response = client.execute(post); System.out.println("Response Code : " + response.getStatusLine().getStatusCode()); } 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(); } }
From source file:MD5.java
public static void main(String[] args) { //String password = args[0]; String password = "test"; MessageDigest digest = null;// ww w .jav a 2 s . c o m try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } try { digest.update(password.getBytes("UTF-8")); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } byte[] rawData = digest.digest(); StringBuffer printable = new StringBuffer(); for (int i = 0; i < rawData.length; i++) { printable.append(carr[((rawData[i] & 0xF0) >> 4)]); printable.append(carr[(rawData[i] & 0x0F)]); } String phpbbPassword = printable.toString(); System.out.println("PHPBB : " + phpbbPassword); System.out.println("MVNFORUM : " + getMD5_Base64(password)); System.out.println("PHPBB->MVNFORUM : " + getBase64FromHEX(phpbbPassword)); }
From source file:com.foxykeep.parcelablecodegenerator.Main.java
public static void main(String[] args) { File fileInputDir = new File("input"); if (!fileInputDir.exists() || !fileInputDir.isDirectory()) { return;/*from w w w . ja v a2 s .co m*/ } ArrayList<FileInfo> fileInfoList = new ArrayList<FileInfo>(); findJsonFiles(fileInputDir, null, fileInfoList); StringBuilder sb = new StringBuilder(); // For each file in the input folder for (FileInfo fileInfo : fileInfoList) { String fileName = fileInfo.file.getName(); System.out.println("Generating code for " + fileName); char[] buffer = new char[2048]; sb.setLength(0); Reader in; try { in = new InputStreamReader(new FileInputStream(fileInfo.file), "UTF-8"); int read; do { read = in.read(buffer, 0, buffer.length); if (read != -1) { sb.append(buffer, 0, read); } } while (read >= 0); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return; } catch (FileNotFoundException e) { e.printStackTrace(); return; } catch (IOException e) { e.printStackTrace(); return; } String content = sb.toString(); if (content.length() == 0) { System.out.println("file is empty."); return; } try { JSONObject root = new JSONObject(content); // Classes generation String classPackage, className, superClassPackage, superClassName; boolean isSuperClassParcelable, hasSubClasses, isAbstract; classPackage = root.getString("package"); className = root.getString("name"); superClassPackage = JsonUtils.getStringFixFalseNull(root, "superClassPackage"); superClassName = JsonUtils.getStringFixFalseNull(root, "superClassName"); isSuperClassParcelable = root.optBoolean("isSuperClassParcelable"); hasSubClasses = root.optBoolean("hasSubClasses"); if (hasSubClasses) { isAbstract = root.optBoolean("isAbstract"); } else { isAbstract = false; } JSONArray fieldJsonArray = root.optJSONArray("fields"); ArrayList<FieldData> fieldDataList; if (fieldJsonArray != null) { fieldDataList = FieldData.getFieldsData(fieldJsonArray); } else { fieldDataList = new ArrayList<FieldData>(); } // Parcelable generation ParcelableGenerator.generate(fileInfo.dirPath, classPackage, className, superClassPackage, superClassName, isSuperClassParcelable, hasSubClasses, isAbstract, fieldDataList); } catch (JSONException e) { e.printStackTrace(); return; } } }
From source file:com.exploringspatial.job.AcladLoaderJob.java
public static void main(String[] args) { if (args.length < 2) { System.out.println("Error: missing output directory path."); System.out.println("Usage: java AcladLoaderJob outputPath eventsCsvFileName"); }/* w ww .jav a 2 s . c o m*/ ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/applicationContext.xml"); AcladLoaderJob acladLoaderJob = (AcladLoaderJob) applicationContext.getBean("acladLoaderJob"); try { acladLoaderJob.run(args); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:org.springside.examples.schedule.TransferOaDataToGx.java
public static void main(String[] args) { // /*from www. j av a2 s . c o 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.thed.zapi.cloud.sample.CreateCycleAndAddTests.java
public static void main(String[] args) throws URISyntaxException, JobProgressException, JSONException, IllegalStateException, IOException { // Replace zephyr baseurl <ZAPI_Cloud_URL> shared with the user for ZAPI Cloud String zephyrBaseUrl = "<ZAPI_Cloud_URL>"; // zephyr accessKey , we can get from Addons >> zapi section String accessKey = "YjE2MjdjMGEtNzExNy0zYjY1LWFkMzQtNjcwMDM3OTljOGkbWluIGFkbWlu"; // zephyr secretKey , we can get from Addons >> zapi section String secretKey = "qufnbimi96Ob2hq3ISF08yZ8HmQw4c1eHGeGlk"; String userName = "admin"; ZFJCloudRestClient client = ZFJCloudRestClient.restBuilder(zephyrBaseUrl, accessKey, secretKey, userName) .build();//w w w . jav a 2 s . c om /** Declare the Variables here **/ Long projectId = 10100l; Long versionId = -1l; String cycleName = "Test Cycle -- API DEMO"; String cycleDescription = "Created by ZAPI CLOUD API"; String createCycleUri = zephyrBaseUrl + "/public/rest/api/1.0/cycle?expand=&clonedCycleId="; /** Cycle Object created - DO NOT EDIT **/ JSONObject createCycleObj = new JSONObject(); createCycleObj.put("name", cycleName); createCycleObj.put("description", cycleDescription); createCycleObj.put("startDate", System.currentTimeMillis()); createCycleObj.put("projectId", projectId); createCycleObj.put("versionId", versionId); StringEntity cycleJSON = null; try { cycleJSON = new StringEntity(createCycleObj.toString()); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } CreateCycleAndAddTests cc = new CreateCycleAndAddTests(); String cycleID = cc.createCycle(createCycleUri, client, accessKey, cycleJSON); System.out.println("Cycle Created with Cycle Id :" + cycleID); /** * Add tests to Cycle IssueId's * */ String addTestsUri = zephyrBaseUrl + "/public/rest/api/1.0/executions/add/cycle/" + cycleID; String[] issueIds = { "SUP-1", "TUR-1" }; //Issue Id's to be added to Test Cycle, add more issueKeys separated by comma JSONObject addTestsObj = new JSONObject(); addTestsObj.put("issues", issueIds); addTestsObj.put("method", "1"); addTestsObj.put("projectId", projectId); addTestsObj.put("versionId", versionId); StringEntity addTestsJSON = null; try { addTestsJSON = new StringEntity(addTestsObj.toString()); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } String ID = cc.addTestsToCycle(addTestsUri, client, accessKey, addTestsJSON); System.out.println("Tests added successfully "); }
From source file:com.thed.zapi.cloud.sample.CreateTestWithTestSteps.java
public static void main(String[] args) throws JSONException, URISyntaxException, ParseException, IOException { final String createTestUri = API_CREATE_TEST.replace("{SERVER}", jiraBaseURL); final String createTestStepUri = API_CREATE_TEST_STEP.replace("{SERVER}", zephyrBaseUrl); /**/* www.j a v a 2 s. c om*/ * Create Test Parameters, declare Create Test Issue fields Declare more * field objects if required */ JSONObject projectObj = new JSONObject(); projectObj.put("id", projectId); // Project ID where the Test to be // Created JSONObject issueTypeObj = new JSONObject(); issueTypeObj.put("id", issueTypeId); // IssueType ID which is Test isse // type JSONObject assigneeObj = new JSONObject(); assigneeObj.put("name", userName); // Username of the assignee JSONObject reporterObj = new JSONObject(); reporterObj.put("name", userName); // Username of the Reporter String testSummary = "Sample Test case With Steps created through ZAPI Cloud"; // Test // Case // Summary/Name /** * Create JSON payload to POST Add more field objects if required * * ***DONOT EDIT BELOW *** */ JSONObject fieldsObj = new JSONObject(); fieldsObj.put("project", projectObj); fieldsObj.put("summary", testSummary); fieldsObj.put("issuetype", issueTypeObj); fieldsObj.put("assignee", assigneeObj); fieldsObj.put("reporter", reporterObj); JSONObject createTestObj = new JSONObject(); createTestObj.put("fields", fieldsObj); System.out.println(createTestObj.toString()); byte[] bytesEncoded = Base64.encodeBase64((userName + ":" + password).getBytes()); String authorizationHeader = "Basic " + new String(bytesEncoded); Header header = new BasicHeader(HttpHeaders.AUTHORIZATION, authorizationHeader); StringEntity createTestJSON = null; try { createTestJSON = new StringEntity(createTestObj.toString()); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } HttpResponse response = null; HttpClient restClient = new DefaultHttpClient(); try { // System.out.println(issueSearchURL); HttpPost createTestReq = new HttpPost(createTestUri); createTestReq.addHeader(header); createTestReq.addHeader("Content-Type", "application/json"); createTestReq.setEntity(createTestJSON); response = restClient.execute(createTestReq); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String testId = null; int statusCode = response.getStatusLine().getStatusCode(); // System.out.println(statusCode); HttpEntity entity1 = response.getEntity(); if (statusCode >= 200 && statusCode < 300) { String string1 = null; try { string1 = EntityUtils.toString(entity1); System.out.println(string1); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } JSONObject createTestResp = new JSONObject(string1); testId = createTestResp.getString("id"); System.out.println("testId :" + testId); } else { try { String string = null; string = EntityUtils.toString(entity1); JSONObject executionResponseObj = new JSONObject(string); System.out.println(executionResponseObj.toString()); throw new ClientProtocolException("Unexpected response status: " + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } /** Create test Steps ***/ /** * Create Steps Replace the step,data,result values as required */ JSONObject testStepJsonObj = new JSONObject(); testStepJsonObj.put("step", "Sample Test Step"); testStepJsonObj.put("data", "Sample Test Data"); testStepJsonObj.put("result", "Sample Expected Result"); /** DONOT EDIT FROM HERE ***/ StringEntity createTestStepJSON = null; try { createTestStepJSON = new StringEntity(testStepJsonObj.toString()); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } String finalURL = createTestStepUri + testId + "?projectId=" + projectId; URI uri = new URI(finalURL); int expirationInSec = 360; JwtGenerator jwtGenerator = client.getJwtGenerator(); String jwt = jwtGenerator.generateJWT("POST", uri, expirationInSec); System.out.println(uri.toString()); System.out.println(jwt); HttpResponse responseTestStep = null; HttpPost addTestStepReq = new HttpPost(uri); addTestStepReq.addHeader("Content-Type", "application/json"); addTestStepReq.addHeader("Authorization", jwt); addTestStepReq.addHeader("zapiAccessKey", accessKey); addTestStepReq.setEntity(createTestStepJSON); try { responseTestStep = restClient.execute(addTestStepReq); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int testStepStatusCode = responseTestStep.getStatusLine().getStatusCode(); System.out.println(testStepStatusCode); System.out.println(response.toString()); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = responseTestStep.getEntity(); String string = null; String stepId = null; try { string = EntityUtils.toString(entity); JSONObject testStepObj = new JSONObject(string); stepId = testStepObj.getString("id"); System.out.println("stepId :" + stepId); System.out.println(testStepObj.toString()); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { try { throw new ClientProtocolException("Unexpected response status: " + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } }