Verify special char is in String before append into StringBuffer

I have following code to verify A special char "X" is in the String before continue adding it to a StringBuffer:
private boolean veriChar(String poem){
if(peom.indexOf("X")==-1) return false;// make sure X is in the String
return true
However, if I only want a single X in String to return true, any method to use? for example: poem=" EXTRA TEXT" (2 Xes here) needs to be rejected to be false.

take this code compile it and see for yourself.
public class Test{
  public static void main(String args[]){
    Test t = new Test();
    System.out.println(""+t.veriChar("MATT"));
    System.out.println(""+t.veriChar("MAX"));
    System.out.println(""+t.veriChar("MAXX"));
  private boolean veriChar(String toCheck){
    return!((toCheck.indexOf("X")<0)||(toCheck.indexOf("X")!=toCheck.lastIndexOf("X")));
} you will see that the first and third ones return false and the second returns true which is as you want.
now an explanation of what is happening.
the method looks like this
private boolean veriChar(String toCheck){
    return!((toCheck.indexOf("X")<0)||(toCheck.indexOf("X")!=toCheck.lastIndexOf("X")));
  }first we check if the special X or whatever exists in the string at all
toCheck.indexOf("X")<0;this returns true for the first test of MATT
now we check if the last occurance in our string of the special X is the same position as the first occurance. if it is then we have only one special X. if not then we have more than one special X.
toCheck.indexOf("X")!=toCheck.lastIndexOf("X")note that we check for not equals so that for MAX it returns false and for MAXX it returns true
so now we have our answers but they are inverted from what we want so we put the ! which gives the boolean opposite. so that the MAX returns true and the other two return false.

Similar Messages

  • Limiting the entry of special chars in a string.

    Hi,
    I have to restrict the entry of any character except (a-z)/(A-Z) and (0-9) in a text field of datatype VARCHAR2. (Forms 10g)
    Is there any built in to implement this instead of verifying every entered character.
    Thanks
    Preeti

    SQL> create table t(v varchar2(40) check (translate(v,'~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','~') is null));
    Table created.
    SQL> insert into t values ('abc123');
    1 row created.
    SQL> insert into t values ('abc+++');
    insert into t values ('abc+++')
    ERROR at line 1:
    ORA-02290: check constraint (SCOTT.SYS_C005284) violated

  • Connection String Special char

    Hello,
    I have a problem with databasenames with special characters in the name:
    (My code works when there is not a special char in the name)
    For example, when my connectionstring would be:  jdbc:sybase:Tds:localhost:2638?ServiceName=BANDENM&W
    I get a java.sql.SQLException: JZ00L: Login failed.  Examine the SQLWarnings chained to this exception for the reason(s). at line 3 while my pasw and login are correct.
    Class.forName("com.sybase.jdbc3.jdbc.SybDriver");
      String connectionString = "jdbc:sybase:Tds:" + config.getHost() + ":" + config.getPort() + "?ServiceName=" + databaseName;
      Connection connection2  = DriverManager.getConnection(connectionString, config.getUser(), config.getPassword());
      //get VC client customer info
      statement = connection2.createStatement();
      resultSet2 = statement.executeQuery("SELECT CNR_SUPP,CNR_CUST,TNR_ID,NM_ID,CNR_VAT_ID,NM_FILTER_ID,CNR_ZIP_ID,CNR_VATCNTRY_ID,NM_TOWN_ID,TOP_COUNTRY.CNR_INTRASTAT FROM TOP_IDENTITY JOIN TOP_COUNTRY ON (TOP_IDENTITY.COD_CNTRY_ID = TOP_COUNTRY.COD_CNTRY)");
    When I add double quotes around the databaseName, I get to line 8 but then I get an error:
    com.sybase.jdbc3.jdbc.SybSQLException: ASA Error -141: Table 'TOP_IDENTITY' not found
    But the table is again, definitely there ...
    I've tried escaping it by replacing & with &amp;
    But no luck.

    1) What version and build are you running for jConnect and SQL Anywhere?
    I’ve used jconn2 and jconn3, for the moment I’m using 3
    SQL Anywhere = 9.0.2.3198 on my developer system
    2) Can you post the output from dbinfo for the database that you testing?
    I'm assuming you mean this:
    Adaptive Server Anywhere Database Engine Version 9.0.2.3198
    Copyright © 1989-2004 Sybase, Inc.
    Portions Copyright © 2002-2004, iAnywhere Solutions, Inc.
    All rights reserved. All unpublished rights reserved.
    This software contains confidential and trade secret information of
    iAnywhere Solutions, Inc.
    Use, duplication or disclosure of the software and documentation
    by the U.S. Government is subject to restrictions set forth in a license
    agreement between the Government and iAnywhere Solutions, Inc. or
    other written agreement specifying the Government's rights to use the
    software and any applicable FAR provisions, for example, FAR 52.227-19.
    iAnywhere Solutions, Inc., One Sybase Drive, Dublin, CA 94568, USA
    4 logical processor(s) on 1 physical processor(s) detected.
    Running on Windows NT 6.1 Build 7601 Service Pack 1
    21688K of memory used for caching
    Minimum cache size: 2048K, maximum cache size: 262144K
    Using a maximum page size of 8192 bytes
    Database server started at Wed Aug 27 2014 14:18
    Trying to start SharedMemory link ...
        SharedMemory link started successfully
    Trying to start NamedPipes link ...
        NamedPipes link started successfully
    Trying to start TDS (TCPIP) link ...
    Starting on port 2638
        TDS (TCPIP) link started successfully
    Now accepting requests
    Starting database "TOPADMINSA9" (W:\TOP\DATA\TOPADMINSA9.db) at Wed Aug 27 2014 14:18
    Transaction log: TOPADMINSA9.log
    Starting checkpoint of "TOPADMINSA9" (TOPADMINSA9.db) at Wed Aug 27 2014 14:18
    Finished checkpoint of "TOPADMINSA9" (TOPADMINSA9.db) at Wed Aug 27 2014 14:18
    Database "TOPADMINSA9" (TOPADMINSA9.db) started at Wed Aug 27 2014 14:18
    Starting database "3051" (w:\TOP\DATA\3051\3051.DB) at Wed Aug 27 2014 14:18
    Starting checkpoint of "3051" (3051.DB) at Wed Aug 27 2014 14:18
    Finished checkpoint of "3051" (3051.DB) at Wed Aug 27 2014 14:18
    Database "3051" (3051.DB) started at Wed Aug 27 2014 14:18
    Starting database "BANDENM&W" (w:\TOP\DATA\BANDENM&W\BANDENM&W.DB) at Wed Aug 27 2014 14:19
    Database "3051" (3051.DB) stopped at Wed Aug 27 2014 14:19
    Starting checkpoint of "BANDENM&W" (BANDENM&W.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "BANDENM&W" (BANDENM&W.DB) at Wed Aug 27 2014 14:19
    Database "BANDENM&W" (BANDENM&W.DB) started at Wed Aug 27 2014 14:19
    Starting database "BRAL" (w:\TOP\DATA\BRAL\BRAL.DB) at Wed Aug 27 2014 14:19
    Transaction log: w:\TOP\DATA\BRAL\BRAL.log
    Starting checkpoint of "BRAL" (BRAL.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "BRAL" (BRAL.DB) at Wed Aug 27 2014 14:19
    Database "BRAL" (BRAL.DB) started at Wed Aug 27 2014 14:19
    Starting checkpoint of "BRAL" (BRAL.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "BRAL" (BRAL.DB) at Wed Aug 27 2014 14:19
    Database "BRAL" (BRAL.DB) stopped at Wed Aug 27 2014 14:19
    Starting database "HARKELIJN" (w:\TOP\DATA\HARKELIJN\HARKELIJN.DB) at Wed Aug 27 2014 14:19
    Transaction log: w:\TOP\DATA\HARKELIJN\HARKELIJN.log
    Starting checkpoint of "HARKELIJN" (HARKELIJN.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "HARKELIJN" (HARKELIJN.DB) at Wed Aug 27 2014 14:19
    Database "HARKELIJN" (HARKELIJN.DB) started at Wed Aug 27 2014 14:19
    Starting checkpoint of "HARKELIJN" (HARKELIJN.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "HARKELIJN" (HARKELIJN.DB) at Wed Aug 27 2014 14:19
    Starting database "BURO56" (w:\TOP\DATA\BURO56\BURO56.DB) at Wed Aug 27 2014 14:19
    Database "HARKELIJN" (HARKELIJN.DB) stopped at Wed Aug 27 2014 14:19
    Transaction log: w:\TOP\DATA\BURO56\BURO56.log
    Starting checkpoint of "BURO56" (BURO56.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "BURO56" (BURO56.DB) at Wed Aug 27 2014 14:19
    Database "BURO56" (BURO56.DB) started at Wed Aug 27 2014 14:19
    Starting checkpoint of "BURO56" (BURO56.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "BURO56" (BURO56.DB) at Wed Aug 27 2014 14:19
    Database "BURO56" (BURO56.DB) stopped at Wed Aug 27 2014 14:19
    Starting database "ENOZEN" (w:\TOP\DATA\ENOZEN\ENOZEN.DB) at Wed Aug 27 2014 14:19
    Transaction log: w:\TOP\DATA\ENOZEN\ENOZEN.log
    Starting checkpoint of "ENOZEN" (ENOZEN.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "ENOZEN" (ENOZEN.DB) at Wed Aug 27 2014 14:19
    Database "ENOZEN" (ENOZEN.DB) started at Wed Aug 27 2014 14:19
    Starting checkpoint of "ENOZEN" (ENOZEN.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "ENOZEN" (ENOZEN.DB) at Wed Aug 27 2014 14:19
    Database "ENOZEN" (ENOZEN.DB) stopped at Wed Aug 27 2014 14:19
    Starting database "ENOCONBVBA" (W:\TOP\DATA\ENOCONBVBA\ENOCONBVBA.DB) at Wed Aug 27 2014 14:19
    Transaction log: W:\TOP\DATA\ENOCONBVBA\ENOCONBVBA.LOG
    Starting checkpoint of "ENOCONBVBA" (ENOCONBVBA.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "ENOCONBVBA" (ENOCONBVBA.DB) at Wed Aug 27 2014 14:19
    Database "ENOCONBVBA" (ENOCONBVBA.DB) started at Wed Aug 27 2014 14:19
    Starting checkpoint of "ENOCONBVBA" (ENOCONBVBA.DB) at Wed Aug 27 2014 14:19
    Finished checkpoint of "ENOCONBVBA" (ENOCONBVBA.DB) at Wed Aug 27 2014 14:19
    Database "ENOCONBVBA" (ENOCONBVBA.DB) stopped at Wed Aug 27 2014 14:19
    3) Can you run the following queries within the application that you are seeing this behavior and provide the results:
      Q1:
         select  user_name,  table_name
              from  systable join sysuser
         where
               table_name in ('TOP_IDENTITY','TOP_COUNTRY')
    27-08-14 14:23:30 [ERROR] TechLogger -  -> com.sybase.jdbc3.jdbc.SybSQLException: ASA Error -141: Table 'sysuser' not found
    Q2:
         select current user from dummy;
    resultSet2.getString("current user")" = DBA

  • Spliting a large string using regular expression which contain special char

    I have huge sting(xml) containing normal character a-z,A-Z and 0-9 as well as special char( <,>,?,&,',",;,/ etc.)
    I need to split this sting where it ends with </document>
    for e.g.
    Original String:
    <document>
    <item>sdf</item>
    <item><text>sd</text</item>
    </document>
    <document>hi</document>
    The above sting has to be splited in to two parts since it is having two document tag.
    Can any body help me to resolve this issue. I can use StringTokenizer,String split method or Regular expression api too.

    manas589 wrote:
    I used DOM and sax parser and got few exception. Again i don't have right to change xml. so i thought to go with RegularExpression or some other way where i can do my job.If the file actually comes in lines like what you posted, you should just be able to compare the contents of each line to see if it contains "</document>" or whatever you're looking for. I wouldn't use regex unless I needed another problem.
    I got excpetion like: Caused by: org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.
         at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
         at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
         at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)So then it isn't even XML.
    Edit: sorry, I just realized why you're considering all of these heavy-duty ideas. It's just that you don't know how to break the string into lines. You do it like this:
    BufferedReader  br = new BufferedReader(new StringReader(theNotXMLString));

  • Issue: Not getting response when the document is having special chars

    Please help following issue: Not getting response when the document is having special chars(Use any doc with special char(ex: &, $, <, >,.....) TestErrorFour.doc
    Error message:
    System.FormatException: Invalid length for a Base-64 char array. at
    System.Convert.FromBase64String(String s) at
    Summarize.Summarizer.AccumulateBroadcast(String filedata, String givenWords) in
    c:\DocumentSummarizer\App_Code\Summarizer.cs:line 66
    Code:
    File 1:
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.Properties;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;
    import org.apache.poi.hwpf.*;
    import org.apache.poi.hwpf.extractor.*;
    import com.lowagie.text.Document;
    import com.lowagie.text.pdf.PRTokeniser;
    import com.lowagie.text.pdf.PdfReader;
    public class DocumentSummarizerClient {
         static Properties loadProperties() {
              Properties prop = new Properties();
              try {
                   prop.load(DocumentSummarizerClient.class.getClassLoader().getResourceAsStream("vep.properties"));
              } catch (Exception ioe) {
                   ioe.printStackTrace();
              return prop;
         public String getSummary(String fileName,String noOfWordsOrPercentage ){
              String summaryInputData ="";
              String summarizedData="";
              String summarizerURL = loadProperties().getProperty("Summarizer.serviceURL");
              try {
                   String fileExtension=fileName.substring(fileName.lastIndexOf(".")+1, fileName.length());
                   if (fileExtension.equalsIgnoreCase("doc")|| fileExtension.equalsIgnoreCase("txt")|| fileExtension.equalsIgnoreCase("pdf")) {
                                  if (fileExtension.equalsIgnoreCase("txt")) {
                                       BufferedReader bufferedReader = new BufferedReader(
                                                 new FileReader(fileName));
                                       String line = null;
                                       while ((line = bufferedReader.readLine()) != null) {
                                            summaryInputData += line;
                                  if(fileExtension.equalsIgnoreCase("doc")){
                                       POIFSFileSystem fs = null;
                                        fs = new POIFSFileSystem(new FileInputStream(fileName));
                                         HWPFDocument doc = new HWPFDocument(fs);
                                         WordExtractor we = new WordExtractor(doc);
                                         String[] paragraphs = we.getParagraphText();
                                         for( int i=0; i<paragraphs .length; i++ ) {
                                            paragraphs[i] = paragraphs.replaceAll("\\cM?\r?\n","");
                                  summaryInputData+= paragraphs[i];
                                  if(fileExtension.equalsIgnoreCase("pdf")){
                                       Document document = new Document();
                   document.open();
                   PdfReader reader = new PdfReader(fileName);
                   int pageCount =reader.getNumberOfPages();
                        for(int i=1;i<=pageCount;i++){
                                  byte[] bytes = reader.getPageContent(i);
                                  PRTokeniser tokenizer = new PRTokeniser(bytes);
                                  StringBuffer buffer = new StringBuffer();
                                  while (tokenizer.nextToken()) {
                                  if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
                                  buffer.append(tokenizer.getStringValue());
                                  summaryInputData += buffer.toString();
                   else{
                        System.out.println("This is Invalid document. Presntly we support only text,word and PDF documents ");
                   // String encoded =new String (summaryInputData.getBytes("ISO-8859-1"),"UTF-8");
                        String encoded=Base64Utils.base64Encode(summaryInputData.getBytes());
                   // encoded =new String (summaryInputData.getBytes("ISO-8859-1"),"UTF-8");
                        String parameters= "base64String="+encoded+"&noOfWordsOrPercentage="+noOfWordsOrPercentage;
                        summarizedData= postRequest(parameters,summarizerURL);
                        String slength= "<string xmlns=\"http://tempuri.org/\">";
                        if(summarizedData.contains("</string>")){
                        summarizedData= summarizedData.substring(summarizedData.indexOf(slength)+slength.length(),summarizedData.indexOf("</string>"));
                        summarizedData = replaceVal(summarizedData);
                        //System.out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?><![CDATA["+summarizedData+"]]>");
                        // System.out.println("Summarized data "+summarizedData);
                        if(summarizedData.contains("Please enter the percentage")){
                             summarizedData="Data given cannot be summarized further";
                   else{
                        System.out.println("Data given cannot be summarized further");
                        summarizedData="";
              } catch (FileNotFoundException e) {
                   return("The File is not found \n\n"+e.toString());
              } catch (IOException e) {
                   return("The File is already in use \n\n"+e.toString());
              } catch (Exception e) {
                   return(e.toString());
              return summarizedData;
         public static String postRequest(String parameters,String webServiceURL) throws Exception{
              Properties systemSettings = System.getProperties();
              systemSettings.put("http.proxyHost", loadProperties().getProperty("proxyHost"));
         systemSettings.put("http.proxyPort", loadProperties().getProperty("proxyPort"));
         System.setProperties(systemSettings);
              String responseXML = "";
              try {
                   URL url = new URL(webServiceURL);
                   URLConnection connection = url.openConnection();
                   HttpURLConnection httpConn = (HttpURLConnection) connection;
                   byte[] requestXML = parameters.getBytes();
                   httpConn.setRequestProperty("Content-Length", String
                             .valueOf(requestXML.length));
                   httpConn.setRequestProperty("Content-Type",
                             "application/x-www-form-urlencoded");
                   httpConn.setRequestMethod("POST");
                   httpConn.setDoOutput(true);
                   httpConn.setDoInput(true);
                   OutputStream out = httpConn.getOutputStream();
                   out.write(requestXML, 0, requestXML.length);
                   out.close();
                   InputStreamReader isr = new InputStreamReader(httpConn
                             .getInputStream());
                   BufferedReader br = new BufferedReader(isr);
                   String temp;
                   String tempResponse = "";
                   while ((temp = br.readLine()) != null)
                        tempResponse = tempResponse + temp;
                   responseXML = tempResponse;
                   br.close();
                   isr.close();
              } catch (java.net.MalformedURLException e) {
                   System.out
                             .println("Error in postRequest(): Secure Service Required");
              } catch (Exception e) {
                   System.out.println("Error in postRequest(): " + e.getMessage());
              return responseXML;
         public String replaceVal(String value) {
                   if (value == null) {
                        value = "";
                   value = value.replace("&lt;", "<");
                   value = value.replace("&gt;", ">");
                   value = value.replace("&amp;", "&");
                   return value;
              public static void main(String[] args) {  
                   DocumentSummarizerClient testdoc=new DocumentSummarizerClient();
                   System.out.println("hello");               
                   testdoc.getSummary("C:\\working_folder\\vep\\UnitTestCases\\VEP1.0\\DocumentSummarizerTestData\\TestErrorFour.doc","100%");     
    Note: Use any doc with special char(ex: &, $, <, >,.....) TestErrorFour.doc
    File 2:
    ---------public class Base64Utils {
    private static byte[] mBase64EncMap, mBase64DecMap;
    * Class initializer. Initializes the Base64 alphabet (specified in RFC-2045).
    static {
    byte[] base64Map = {
    (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F',
    (byte)'G', (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L',
    (byte)'M', (byte)'N', (byte)'O', (byte)'P', (byte)'Q', (byte)'R',
    (byte)'S', (byte)'T', (byte)'U', (byte)'V', (byte)'W', (byte)'X',
    (byte)'Y', (byte)'Z',
    (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f',
    (byte)'g', (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l',
    (byte)'m', (byte)'n', (byte)'o', (byte)'p', (byte)'q', (byte)'r',
    (byte)'s', (byte)'t', (byte)'u', (byte)'v', (byte)'w', (byte)'x',
    (byte)'y', (byte)'z',
    (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5',
    (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/'};
    mBase64EncMap = base64Map;
    mBase64DecMap = new byte[128];
    for (int i=0; i<mBase64EncMap.length; i++)
    mBase64DecMap[mBase64EncMap[i]] = (byte) i;
    * This class isn't meant to be instantiated.
    private Base64Utils() {
    * Encodes the given byte[] using the Base64-encoding,
    * as specified in RFC-2045 (Section 6.8).
    * @param aData the data to be encoded
    * @return the Base64-encoded <var>aData</var>
    * @exception IllegalArgumentException if NULL or empty array is passed
    public static String base64Encode(byte[] aData) {
    if ((aData == null) || (aData.length == 0))
    throw new IllegalArgumentException("Can not encode NULL or empty byte array.");
    byte encodedBuf[] = new byte[((aData.length+2)/3)*4];
    // 3-byte to 4-byte conversion
    int srcIndex, destIndex;
    for (srcIndex=0, destIndex=0; srcIndex < aData.length-2; srcIndex += 3) {
    encodedBuf[destIndex++] = mBase64EncMap[(aData[srcIndex] >>> 2) & 077];
    encodedBuf[destIndex++] = mBase64EncMap[(aData[srcIndex+1] >>> 4) & 017 |
    (aData[srcIndex] << 4) & 077];
    encodedBuf[destIndex++] = mBase64EncMap[(aData[srcIndex+2] >>> 6) & 003 |
    (aData[srcIndex+1] << 2) & 077];
    encodedBuf[destIndex++] = mBase64EncMap[aData[srcIndex+2] & 077];
    // Convert the last 1 or 2 bytes
    if (srcIndex < aData.length) {
    encodedBuf[destIndex++] = mBase64EncMap[(aData[srcIndex] >>> 2) & 077];
    if (srcIndex < aData.length-1) {
    encodedBuf[destIndex++] = mBase64EncMap[(aData[srcIndex+1] >>> 4) & 017 |
    (aData[srcIndex] << 4) & 077];
    encodedBuf[destIndex++] = mBase64EncMap[(aData[srcIndex+1] << 2) & 077];
    else {
    encodedBuf[destIndex++] = mBase64EncMap[(aData[srcIndex] << 4) & 077];
    // Add padding to the end of encoded data
    while (destIndex < encodedBuf.length) {
    encodedBuf[destIndex] = (byte) '=';
    destIndex++;
    String result = new String(encodedBuf);
    return result;
    * Decodes the given Base64-encoded data,
    * as specified in RFC-2045 (Section 6.8).
    * @param aData the Base64-encoded aData.
    * @return the decoded <var>aData</var>.
    * @exception IllegalArgumentException if NULL or empty data is passed
    public static byte[] base64Decode(String aData) {
    if ((aData == null) || (aData.length() == 0))
    throw new IllegalArgumentException("Can not decode NULL or empty string.");
    byte[] data = aData.getBytes();
    // Skip padding from the end of encoded data
    int tail = data.length;
    while (data[tail-1] == '=')
    tail--;
    byte decodedBuf[] = new byte[tail - data.length/4];
    // ASCII-printable to 0-63 conversion
    for (int i = 0; i < data.length; i++)
    data[i] = mBase64DecMap[data[i]];
    // 4-byte to 3-byte conversion
    int srcIndex, destIndex;
    for (srcIndex = 0, destIndex=0; destIndex < decodedBuf.length-2;
    srcIndex += 4, destIndex += 3) {
    decodedBuf[destIndex] = (byte) ( ((data[srcIndex] << 2) & 255) |
    ((data[srcIndex+1] >>> 4) & 003) );
    decodedBuf[destIndex+1] = (byte) ( ((data[srcIndex+1] << 4) & 255) |
    ((data[srcIndex+2] >>> 2) & 017) );
    decodedBuf[destIndex+2] = (byte) ( ((data[srcIndex+2] << 6) & 255) |
    (data[srcIndex+3] & 077) );
    // Handle last 1 or 2 bytes
    if (destIndex < decodedBuf.length)
    decodedBuf[destIndex] = (byte) ( ((data[srcIndex] << 2) & 255) |
    ((data[srcIndex+1] >>> 4) & 003) );
    if (++destIndex < decodedBuf.length)
    decodedBuf[destIndex] = (byte) ( ((data[srcIndex+1] << 4) & 255) |
    ((data[srcIndex+2] >>> 2) & 017) );
    return decodedBuf;
    issue 2: Exception when passing 2MB .txt file
    Steps to reproduce:
    Call getSummary() with 2MB .txt file
    Actual:
    The following exception has occured:
    1. Error in postRequest(): Unexpected end of file from server
    java.lang.NullPointerException
    Please provide your precious feedback/suggestions.
    Thanks in advance…..
    Edited by: EJP on 15/03/2011 16:52: added code tags. Please use them. Code is unreadable otherwise.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Thanks for your response….
    This is enhancement project and some one develops long back.
    Regarding point (b) You should be using the java.net.URLEncoder to encode URL parameters, not a base64 encoder.
    DocumentSummarizerClient.java I am using base64
    Ex:
    // String encoded =new String (summaryInputData.getBytes("ISO-8859-1"),"UTF-8");
                        String encoded=Base64Utils.base64Encode(summaryInputData.getBytes());
                   // encoded =new String (summaryInputData.getBytes("ISO-8859-1"),"UTF-8");
                        String parameters= "base64String="+encoded+"&noOfWordsOrPercentage="+noOfWordsOrPercentage;
                        summarizedData= postRequest(parameters,summarizerURL);
                        String slength= "<string xmlns=\"http://tempuri.org/\">";
                        if(summarizedData.contains("</string>")){
                        summarizedData= summarizedData.substring(summarizedData.indexOf(slength)+slength.length(),summarizedData.indexOf("</string>"));
                        summarizedData = replaceVal(summarizedData);
                        //System.out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?><![CDATA["+summarizedData+"]]>");
                        System.out.println("Summarized data "+summarizedData);
                        if(summarizedData.contains("Please enter the percentage")){
                             summarizedData="Data given cannot be summarized further";
    Above specific please I need to modify to resolve above issue.
    Could you please suggest me what changes I need to do.
    Waiting for positive response.

  • Page encoding / charset / special chars / NON-ASCII chars

    Whenever special characters are used in our environment, the data is stored incorrect ...
    ® gets converted to ®
    and other special chars gets converted to other special chars ... the strange thing is that some inputText fields in some pages work just fine ..chars dont get converted and it happend in some other many pages ...not sure whats going on ..I tried to change the charset or the pageEncoding of the pages or even manually using the setPageEncoding in the reequest and in the response ..with no luck ...when I print the request params ..the values are converted, so ma not sure at what stage the string get converted and how to prevent it ...
    Charset of the jsp-page is UTF-8. Need help here please.
    Thanks.

    You must verify that all resources are in UTF-8. There are a couple of places you have to check:
    Compiler encoding
    Embedded OC4J JSP Compiler options
    Project settings
    After that it worked for me.
    Timo

  • Getting parameters from URL: use of Special Chars

    I'm unable to retrieve the Special Chars from URL parameters.  Does someone have an idea where to look for?
    Examples where no Special Chars is retrieved :
    ...App?param=Aménagement
    ...App?param=Am<é>nagement
    ...App?param=Am%E9nagement
    I'm using this code :
              IWDProtocolAdapter protocolAdapter =
                   WDProtocolAdapter.getProtocolAdapter();
              IWDRequest request = protocolAdapter.getRequestObject();
                                    String param = request.getParameter("param");
    Thanks!

    okay, So if I use :
    ...App?param=Am%E9+nagement
    How would you then integrate URLDecoder.decode in the following code?
    IWDProtocolAdapter protocolAdapter =
         WDProtocolAdapter.getProtocolAdapter();
    IWDRequest request = protocolAdapter.getRequestObject();
    String param = request.getParameter("param");

  • Dealing with MS Word special chars

    Hi,
    Is there a java.String method (or similar) which will replace MS Word special chars - such as "culry apostrophes" - with HTML compliant versions?
    cheers
    Hugh
    Edited by: inabind on Aug 11, 2008 7:39 AM

    Yes. Oddly enough their names start with "replace".
    But you don't necessarily need to convert the left curly quote to &#2017; or whatever it converts to. You could also use UTF-8 as your HTML's encoding and just leave that character as is.

  • Need help in replacing special characters in a string

    Hi,
    please let me know the best way to replace all the special characters in a string with space.
    other than alphabets and numbers
    with regards.
    sumanth.

    please let me know the best way to replace all the special characters in a string with space.
    other than alphabets and numbers
    >
    Sumanth Nag Kristam wrote:
    > actually i need to replace hexa decimal char 0X1A in a string.... that is 'substitue' as per the chart
    > any pointers....
    >
    > chk the link for the ASCII codes
    > http://www.techonthenet.com/ascii/chart.php
    But in Hexa decimal value there is no special characters?

  • How can I Retrieve special chars from a HTTP Request??

    Hi,
    I want to retrieve special chars from a request
    Chars like accents used in spanish languages or symbols?
    Is there any way to do it
    Thanks in advance
    Alejandro Arredondo

    This is my problem
    For example:
    This is my form:
    <form>
    <input type="text" name="test">
    </form>
    I do write a char on the text area. Something like "?" or "?"
    or some words with accents
    When I retrieve the value with
    String value = request.getParameter("test");
    and print it
    out.println("TEST= " + test);
    It prints another symbol that isn't the one I sent in my form.
    why?
    Thanks

  • Problem with special chars in BLOB datatype using contains keyword

    Facing problem, when part searching with special chars in BLOB datatype. It is considering the non alpha-numeric chars as a separtor in a provided string
    EX:
    SELECT *
    FROM RESUME_TEST P,grst_candidate d
    WHERE d.candidate_id = p.candidate_id
    AND CONTAINS(P.CAND_RESUME,'%VB.NET%',1) > 0
    Strings: , VB.NET , PL/SQL AS/400 , C etc..
    Followed the below approaches
    1) created a table:
    Syntax: create table resume_Test(cand_id number(10),cand_resume blob);
    2) inserted the values into this table upto 60,000
    3) created a context index
    3.1 created preferences
    Syntax:
    BEGIN
    ctx_ddl.create_preference('try_lexer3','BASIC_LEXER');
    ctx_ddl.set_attribute('try_lexer3','printjoins','-_~!@#$%^&*(){}[],=?\;|><.+');
    END;
    3.2 created context index
    Syntax:
    CREATE INDEX CANDRESUME_CTX_IDX ON resume_test (cand_resume)
    INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS ('LEXER try_lexer3 memory 500M');
    4) while executing this index, it is taking much time approx 6 hrs(plz explain why it is taking time)
    5) Problems:
    5.1 when searching with string(VB.NET , PL/SQL AS/400 , C etc..) it is considering the special char as a separator
    5.2 used escape char (\) also, but no effect
    5.3 when searching with single char, it is giving error (ORA-29902,ORA-20000,DRG-51030)
    5.4 getting the above error with wild card chars (& ,_, (),{},[])
    So, please explain the clear scenarios, why am getting this error , and how to get the proper results.

    Have you tried adding the / char to the printjoin characters?
    Indexing can take a lot of time, depending on the amount of data and your machine's power. You could try to parallelize the index creation and / or assign more memory
    CREATE INDEX CANDRESUME_CTX_IDX ON resume_test (cand_resume)
    INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS ('LEXER try_lexer3 memory 2000M') PARALLEL 8;

  • Replacing a special character in a string with another string

    Hi
    I need to replace a special character in a string with another string.
    Say there is a string -  "abc's def's are alphabets"
    and i need to replace all the ' (apostrophe) with &apos& ..which should look like as below
    "abc&apos&s def&apos&s are alphabets" .
    Kindly let me know how this requirement can be met.
    Regards
    Sukumari

    REPLACE
    Syntax Forms
    Pattern-based replacement
    1. REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF]
    pattern
              IN [section_of] dobj WITH new
              [IN {BYTE|CHARACTER} MODE]
              [{RESPECTING|IGNORING} CASE]
              [REPLACEMENT COUNT rcnt]
              { {[REPLACEMENT OFFSET roff]
                 [REPLACEMENT LENGTH rlen]}
              | [RESULTS result_tab|result_wa] }.
    Position-based replacement
    2. REPLACE SECTION [OFFSET off] [LENGTH len] OF dobj WITH new
                      [IN {BYTE|CHARACTER} MODE].
    Effect
    This statement replaces characters or bytes of the variable dobj by characters or bytes of the data object new. Here, position-based and pattern-based replacement are possible.
    When the replacement is executed, an interim result without a length limit is implicitly generated and the interim result is transferred to the data object dobj. If the length of the interim result is longer than the length of dobj, the data is cut off on the right in the case of data objects of fixed length. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or hexadecimal zeroes. Data objects of variable length are adjusted. If data is cut off to the right when the interim result is assigned, sy-subrc is set to 2.
    In the case of character string processing, the closing spaces are taken into account for data objects dobj of fixed length; they are not taken into account in the case of new.
    System fields
    sy-subrc Meaning
    0 The specified section or subsequence was replaced by the content of new and the result is available in full in dobj.
    2 The specified section or subsequence was replaced in dobj by the contents of new and the result of the replacement was cut off to the right.
    4 The subsequence in sub_string was not found in dobj in the pattern-based search.
    8 The data objects sub_string and new contain double-byte characters that cannot be interpreted.
    Note
    These forms of the statement REPLACE replace the following obsolete form:
    REPLACE sub_string WITH
    Syntax
    REPLACE sub_string WITH new INTO dobj
            [IN {BYTE|CHARACTER} MODE]
            [LENGTH len].
    Extras:
    1. ... IN {BYTE|CHARACTER} MODE
    2. ... LENGTH len
    Effect
    This statement searches through a byte string or character string dobj for the subsequence specified in sub_string and replaces the first byte or character string in dobj that matches sub_string with the contents of the data object new.
    The memory areas of sub_string and new must not overlap, otherwise the result is undefined. If sub_string is an empty string, the point before the first character or byte of the search area is found and the content of new is inserted before the first character.
    During character string processing, the closing blank is considered for data objects dobj, sub_string and new of type c, d, n or t.
    System Fields
    sy-subrc Meaning
    0 The subsequence in sub_string was replaced in the target field dobj with the content of new.
    4 The subsequence in sub_string could not be replaced in the target field dobj with the contents of new.
    Note
    This variant of the statement REPLACE will be replaced, beginning with Release 6.10, with a new variant.
    Addition 1
    ... IN {BYTE|CHARACTER} MODE
    Effect
    The optional addition IN {BYTE|CHARACTER} MODE determines whether byte or character string processing will be executed. If the addition is not specified, character string processing is executed. Depending on the processing type, the data objects sub_string, new, and dobj must be byte or character type.
    Addition 2
    ... LENGTH len
    Effect
    If the addition LENGTH is not specified, all the data objects involved are evaluated in their entire length. If the addition LENGTH is specified, only the first len bytes or characters of sub_string are used for the search. For len, a data object of the type i is expected.
    If the length of the interim result is longer than the length of dobj, data objects of fixed length will be cut off to the right. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or with hexadecimal 0. Data objects of variable length are adapted.
    Example
    After the replacements, text1 contains the complete content "I should know that you know", while text2 has the cut-off content "I should know that".
    DATA:   text1      TYPE string       VALUE 'I know you know',
            text2(18)  TYPE c LENGTH 18  VALUE 'I know you know',
            sub_string TYPE string       VALUE 'know',
            new        TYPE string       VALUE 'should know that'.
    REPLACE sub_string WITH new INTO text1.
    REPLACE sub_string WITH new INTO text2.

  • How to remove last char in a string by space

    I have to implement backspace application(remove a last char in a string , when we pressed a button).
    for ex: I enter the no
    1234
    instead of 1236
    So when i press a button on the JWindow... it should display
    123
    so that i can enter 6 now.
    I tried to display the string "123 " instead over "1234" but it is not working when the no background is specified. but works fine when a background color is specified.
    The string is displayed as
    Graphics2D g = (Graphics2D)window.getGraphics();
    AttributedString as = new AttributedString(string, map);
    g.drawString(as.getIterator(),x,y);
    In the map, the background is set to NO_BACKGROUND.
    Thanks and regards

    Deja vu. I saw this kind of post before, and I'm sure
    it was today.http://forum.java.sun.com/thread.jspa?threadID=588110&tstart=0
    Here it is.

  • SLM2048 - Password problems with special chars

    Hi all,
    We´ve got a SLM2048 in use  (most current FW) and I wanted to apply our new password standards  onto that switch. So I changed the password of the user admin and used  special chars, which were =&!= and clicked update and save changes. I  now know, that I should have been using only alphanumerical characters,  but why is there no routine that checks the PW for conformance, before  writing it onto the switch.
    Problem now is, that I am unable to login and  don´t want to do a hard reset, because the configuration would be lost. I  know there should have been a rescue admin user, but there is none.  What can I do now? Any chance that a cisco engineer could get in contact  with me to debug the entered password in the lab and who could then  tell me what was saved to ROM or how I can login again?
    Thanks,
    Philip

    If your switch has a console port, you can try this:
    http://www.opendreams.net/jesse/doc/linksys_srw_switch_password_recovery.txt
    http://www.cisco.com/en/US/products/ps9967/products_qanda_item09186a0080a36735.shtml
    HTH,
    Andrew Lissitz

  • Maintain special char in standard text

    Hi Guru,
    I try to add special character such as &, '' etc in standard text thru web UI.
    But Somehow system cannot identify the special char.
    Does anyone come across this before?

    Hi Jess,
    Refer to this links
    Re: How to create this in standard text
    Re: How to insert special symbols in standard text
    hope this will useful to you,,,
    Regards!

Maybe you are looking for

  • Full Screen Resolution gone with 10.5.2 update

    Hi there, I´m using a MBP (latest) with a NEC Spectraview 2690. Plugged in using 10.5.1 - running 1920 x 1200 / 60 Hz via DVI. Fine. After update to 10.5.2 the highest resolution 1440 x 900 and "Standard LCD". What´s wrong?

  • GRC 10 BRM - Approve Single Role assignment in Business Roles

    Hello, I want to set up a workflow where any Single Role assigned to a Business Role requires an approval of the Single Role Owner. The thing is that my customer doesn't have a Security Administrator, so what they want is that each Single Role Owner

  • Problems on bootup

    1. I'm experiencing some errors showing up on bootup. I'm using Voodoo. My dmesg is (the errors): drivers/usb/input/hid-core.c: v2.6:USB HID core driver end_request: I/O error, dev sr0, sector 1413968 Buffer I/O error on device sr0, logical block 353

  • Custom Name Metadata? Download Path Settings?

    Is there a way to use metadata in setting the custom name? I was hoping to be able to use a naming convention like \YYYY\MM-DD Descriptive Name. I used a tool on my PC to this and I really prefer this format to all others. I assume there must be a wa

  • Ati Radeon no HDMI output

    Hi, I'm on a hybrid-graphics Intel/Ati HP dv6 and I'm trying to connect the HDMI video output to my LED TV, but xrandr doesn't recognize that video output. $ xrandr --prop ~ Screen 0: minimum 320 x 200, current 1366 x 768, maximum 32767 x 32767 LVDS1