List of usage examples for java.io UnsupportedEncodingException toString
public String toString()
From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java
@Override public List<String> findCountryByPropertyNameAndTestCase(String test, String testcase, String property) { List<String> result = new ArrayList<String>(); final String query = "SELECT country FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND hex(`property`) like hex(?)"; Connection connection = this.databaseSpring.connect(); try {// www .j av a 2 s .co m PreparedStatement preStat = connection.prepareStatement(query); try { preStat.setString(1, test); preStat.setString(2, testcase); preStat.setBytes(3, property.getBytes("UTF-8")); ResultSet resultSet = preStat.executeQuery(); try { while (resultSet.next()) { String country = resultSet.getString("country"); if (country != null && !"".equals(country)) { result.add(country); } } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } catch (UnsupportedEncodingException ex) { LOG.error(ex.toString()); } finally { preStat.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { LOG.warn(e.toString()); } } if (result.size() == 0) { return null; } return result; }
From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java
@Override public void insertTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties) throws CerberusException { boolean throwExcep = false; StringBuilder query = new StringBuilder(); query.append(/*from w w w .j av a2s .com*/ "INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property` ,`Description`,`Type`"); query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`) "); query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { preStat.setString(1, testCaseCountryProperties.getTest()); preStat.setString(2, testCaseCountryProperties.getTestCase()); preStat.setString(3, testCaseCountryProperties.getCountry()); preStat.setBytes(4, testCaseCountryProperties.getProperty().getBytes("UTF-8")); preStat.setBytes(5, testCaseCountryProperties.getDescription().getBytes("UTF-8")); preStat.setString(6, testCaseCountryProperties.getType()); preStat.setString(7, testCaseCountryProperties.getDatabase()); preStat.setBytes(8, testCaseCountryProperties.getValue1().getBytes("UTF-8")); preStat.setBytes(9, testCaseCountryProperties.getValue2().getBytes("UTF-8")); preStat.setInt(10, testCaseCountryProperties.getLength()); preStat.setInt(11, testCaseCountryProperties.getRowLimit()); preStat.setString(12, testCaseCountryProperties.getNature()); preStat.setInt(13, testCaseCountryProperties.getRetryNb()); preStat.setInt(14, testCaseCountryProperties.getRetryPeriod()); preStat.executeUpdate(); throwExcep = false; } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } catch (UnsupportedEncodingException ex) { LOG.error(ex.toString()); } finally { preStat.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { LOG.warn(e.toString()); } } if (throwExcep) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE)); } }
From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java
@Override public void updateTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties) throws CerberusException { boolean throwExcep = false; StringBuilder query = new StringBuilder(); query.append("UPDATE testcasecountryproperties SET "); query.append(// w w w.ja v a2s .c o m " `Description` = ?, `Type` = ? ,`Database` = ? ,Value1 = ?,Value2 = ?,`Length` = ?, RowLimit = ?, `Nature` = ? , `RetryNb` = ? , `RetryPeriod` = ? "); query.append(" WHERE Test = ? AND TestCase = ? AND Country = ? AND hex(`Property`) like hex(?)"); Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { preStat.setBytes(1, testCaseCountryProperties.getDescription().getBytes("UTF-8")); preStat.setString(2, testCaseCountryProperties.getType()); preStat.setString(3, testCaseCountryProperties.getDatabase()); preStat.setBytes(4, testCaseCountryProperties.getValue1().getBytes("UTF-8")); preStat.setBytes(5, testCaseCountryProperties.getValue2().getBytes("UTF-8")); preStat.setInt(6, testCaseCountryProperties.getLength()); preStat.setInt(7, testCaseCountryProperties.getRowLimit()); preStat.setString(8, testCaseCountryProperties.getNature()); preStat.setInt(9, testCaseCountryProperties.getRetryNb()); preStat.setInt(10, testCaseCountryProperties.getRetryPeriod()); preStat.setString(11, testCaseCountryProperties.getTest()); preStat.setString(12, testCaseCountryProperties.getTestCase()); preStat.setString(13, testCaseCountryProperties.getCountry()); preStat.setBytes(14, testCaseCountryProperties.getProperty().getBytes("UTF-8")); preStat.executeUpdate(); throwExcep = false; } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } catch (UnsupportedEncodingException ex) { LOG.error(ex.toString()); } finally { preStat.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { LOG.warn(e.toString()); } } if (throwExcep) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE)); } }
From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java
@Override public List<String> findCountryByProperty(TestCaseCountryProperties testCaseCountryProperties) { List<String> list = null; final StringBuilder query = new StringBuilder(); query.append("SELECT country FROM testcasecountryproperties WHERE test = ? AND testcase = ?"); query.append(/*from ww w. j av a 2 s.c om*/ " AND HEX(`property`) = hex(?) AND `type` =? AND `database` =? AND hex(`value1`) like hex( ? ) AND hex(`value2`) like hex( ? ) AND `length` = ? "); query.append(" AND `rowlimit` = ? AND `nature` = ?"); // Debug message on SQL. if (LOG.isDebugEnabled()) { LOG.debug("SQL : " + query.toString()); } Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { preStat.setString(1, testCaseCountryProperties.getTest()); preStat.setString(2, testCaseCountryProperties.getTestCase()); preStat.setBytes(3, testCaseCountryProperties.getProperty().getBytes("UTF-8")); preStat.setString(4, testCaseCountryProperties.getType()); preStat.setString(5, testCaseCountryProperties.getDatabase()); preStat.setBytes(6, testCaseCountryProperties.getValue1().getBytes("UTF-8")); preStat.setBytes(7, testCaseCountryProperties.getValue2().getBytes("UTF-8")); preStat.setString(8, String.valueOf(testCaseCountryProperties.getLength())); preStat.setString(9, String.valueOf(testCaseCountryProperties.getRowLimit())); preStat.setString(10, testCaseCountryProperties.getNature()); ResultSet resultSet = preStat.executeQuery(); try { list = new ArrayList<String>(); String valueToAdd; while (resultSet.next()) { valueToAdd = resultSet.getString("Country") == null ? "" : resultSet.getString("Country"); list.add(valueToAdd); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } catch (UnsupportedEncodingException ex) { LOG.error(ex.toString()); } finally { preStat.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { LOG.warn(e.toString()); } } return list; }
From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java
@Override public TestCaseCountryProperties findTestCaseCountryPropertiesByKey(String test, String testcase, String country, String property) throws CerberusException { TestCaseCountryProperties result = null; boolean throwException = false; final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ? AND hex(`property`) = hex(?)"; Connection connection = this.databaseSpring.connect(); try {/*ww w.ja v a 2s . co m*/ PreparedStatement preStat = connection.prepareStatement(query); try { preStat.setString(1, test); preStat.setString(2, testcase); preStat.setString(3, country); preStat.setBytes(4, property.getBytes("UTF-8")); ResultSet resultSet = preStat.executeQuery(); try { if (resultSet.first()) { String description = resultSet.getString("description"); String type = resultSet.getString("type"); String database = resultSet.getString("database"); String value1 = resultSet.getString("value1"); String value2 = resultSet.getString("value2"); int length = resultSet.getInt("length"); int rowLimit = resultSet.getInt("rowLimit"); String nature = resultSet.getString("nature"); int retryNb = resultSet.getInt("RetryNb"); int retryPeriod = resultSet.getInt("RetryPeriod"); result = factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod); } else { throwException = true; } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } catch (UnsupportedEncodingException ex) { LOG.error(ex.toString()); } finally { preStat.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { LOG.warn(e.toString()); } } if (throwException) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND)); } return result; }
From source file:com.duroty.utils.mail.MessageUtilities.java
/** * Encode UTF strings into mail addresses. * * @param string DOCUMENT ME!/*from www . j ava2 s .c om*/ * @param charset DOCUMENT ME! * * @return DOCUMENT ME! * * @throws MessagingException DOCUMENT ME! */ public static InternetAddress[] encodeAddresses(String string, String charset) throws MessagingException { if (string == null) { return null; } // parse the string into the internet addresses // NOTE: these will NOT be character encoded InternetAddress[] xaddresses = InternetAddress.parse(string); // now encode each to the given character set if (charset != null) { for (int xindex = 0; xindex < xaddresses.length; xindex++) { String xpersonal = xaddresses[xindex].getPersonal(); try { if (xpersonal != null) { if (charset != null) { xaddresses[xindex].setPersonal(xpersonal, charset); } else { xaddresses[xindex].setPersonal(xpersonal, "ISO-8859-1"); } } } catch (UnsupportedEncodingException xex) { throw new MessagingException(xex.toString()); } } } return xaddresses; }
From source file:com.piusvelte.taplock.client.core.TapLockSettings.java
@Override protected void onResume() { super.onResume(); Intent intent = getIntent();//from w w w. j a v a2s .co m if (mInWriteMode) { if (intent != null) { String action = intent.getAction(); if (mInWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) && intent.hasExtra(EXTRA_DEVICE_NAME)) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); String name = intent.getStringExtra(EXTRA_DEVICE_NAME); if ((tag != null) && (name != null)) { // write the device and address String lang = "en"; // don't write the passphrase! byte[] textBytes = name.getBytes(); byte[] langBytes = null; int langLength = 0; try { langBytes = lang.getBytes("US-ASCII"); langLength = langBytes.length; } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } int textLength = textBytes.length; byte[] payload = new byte[1 + langLength + textLength]; // set status byte (see NDEF spec for actual bits) payload[0] = (byte) langLength; // copy langbytes and textbytes into payload if (langBytes != null) { System.arraycopy(langBytes, 0, payload, 1, langLength); } System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength); NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload); NdefMessage message = new NdefMessage( new NdefRecord[] { record, NdefRecord.createApplicationRecord(getPackageName()) }); // Get an instance of Ndef for the tag. Ndef ndef = Ndef.get(tag); if (ndef != null) { try { ndef.connect(); if (ndef.isWritable()) { ndef.writeNdefMessage(message); } ndef.close(); Toast.makeText(this, "tag written", Toast.LENGTH_LONG).show(); } catch (IOException e) { Log.e(TAG, e.toString()); } catch (FormatException e) { Log.e(TAG, e.toString()); } } else { NdefFormatable format = NdefFormatable.get(tag); if (format != null) { try { format.connect(); format.format(message); format.close(); Toast.makeText(getApplicationContext(), "tag written", Toast.LENGTH_LONG); } catch (IOException e) { Log.e(TAG, e.toString()); } catch (FormatException e) { Log.e(TAG, e.toString()); } } } mNfcAdapter.disableForegroundDispatch(this); } } } mInWriteMode = false; } else { SharedPreferences sp = getSharedPreferences(KEY_PREFS, MODE_PRIVATE); onSharedPreferenceChanged(sp, KEY_DEVICES); // check if configuring a widget if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { final String[] displayNames = TapLock.getDeviceNames(mDevices); final int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle("Select device for widget") .setItems(displayNames, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // set the successful widget result Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); setResult(RESULT_OK, resultValue); // broadcast the new widget to update JSONObject deviceJObj = mDevices.get(which); dialog.cancel(); TapLockSettings.this.finish(); try { sendBroadcast(TapLock .getPackageIntent(TapLockSettings.this, TapLockWidget.class) .setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) .putExtra(EXTRA_DEVICE_NAME, deviceJObj.getString(KEY_NAME))); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }).create(); mDialog.show(); } } } // start the service before binding so that the service stays around for faster future connections startService(TapLock.getPackageIntent(this, TapLockService.class)); bindService(TapLock.getPackageIntent(this, TapLockService.class), this, BIND_AUTO_CREATE); int serverVersion = sp.getInt(KEY_SERVER_VERSION, 0); if (mShowTapLockSettingsInfo && (mDevices.size() == 0)) { if (serverVersion < SERVER_VERSION) sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit(); mShowTapLockSettingsInfo = false; Intent i = TapLock.getPackageIntent(this, TapLockInfo.class); i.putExtra(EXTRA_INFO, getString(R.string.info_taplocksettings)); startActivity(i); } else if (serverVersion < SERVER_VERSION) { // TapLockServer has been updated sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit(); mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle(R.string.ttl_hasupdate) .setMessage(R.string.msg_hasupdate) .setNeutralButton(R.string.button_getserver, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mDialog = new AlertDialog.Builder(TapLockSettings.this) .setTitle(R.string.msg_pickinstaller) .setItems(R.array.installer_entries, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); final String installer_file = getResources() .getStringArray(R.array.installer_values)[which]; mDialog = new AlertDialog.Builder(TapLockSettings.this) .setTitle(R.string.msg_pickdownloader) .setItems(R.array.download_entries, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); String action = getResources() .getStringArray( R.array.download_values)[which]; if (ACTION_DOWNLOAD_SDCARD.equals(action) && copyFileToSDCard(installer_file)) Toast.makeText(TapLockSettings.this, "Done!", Toast.LENGTH_SHORT) .show(); else if (ACTION_DOWNLOAD_EMAIL .equals(action) && copyFileToSDCard( installer_file)) { Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND); emailIntent.setType( "application/java-archive"); emailIntent.putExtra(Intent.EXTRA_TEXT, getString( R.string.email_instructions)); emailIntent.putExtra( Intent.EXTRA_SUBJECT, getString(R.string.app_name)); emailIntent.putExtra( Intent.EXTRA_STREAM, Uri.parse("file://" + Environment .getExternalStorageDirectory() .getPath() + "/" + installer_file)); startActivity(Intent.createChooser( emailIntent, getString( R.string.button_getserver))); } } }) .create(); mDialog.show(); } }).create(); mDialog.show(); } }).create(); mDialog.show(); } } }
From source file:org.jivesoftware.community.util.StringUtils.java
public static String encodeBase64(String data) { byte bytes[] = null; try {// w ww . j a va 2 s . co m bytes = data.getBytes("UTF-8"); } catch (UnsupportedEncodingException uee) { Log.error(uee.toString()); } return encodeBase64(bytes); }
From source file:org.jivesoftware.community.util.StringUtils.java
public static synchronized String hash(String data) { if (digest == null) try {// ww w . j ava 2s .c o m digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException nsae) { Log.error("Failed to load the MD5 MessageDigest. Jive will be unable to function normally.", nsae); } try { digest.update(data.getBytes("utf-8")); } catch (UnsupportedEncodingException e) { Log.error(e.toString()); throw new UnsupportedOperationException( (new StringBuilder()).append("Error computing hash: ").append(e.getMessage()).toString()); } return encodeHex(digest.digest()); }
From source file:hackathon.openrice.CardsActivity.java
public JSONArray getJSONFromUrl(String url) { InputStream is = null;/*from www . j a v a2 s. c o m*/ JSONArray jObj = null; String json = ""; // Making HTTP request try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONArray(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } // return JSON String return jObj; }