kathir je

Greenhorn
+ Follow
since Jun 07, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kathir je


Thanks, Stephen for the sample template. Could you please help me with the code as still working on the building logic?
3 years ago
Stephen,

Could you please kindly help me with a code snippet?
3 years ago
I have a list of file paths as below

Example,
 /B/B/C/D/1.txt
 /C/E/F/D
 /B/F/F/D
 /C/B/C/D/R/3.txt

I need to build a a json structure as hierarchy or parent child array so that i can build the json structure

Example,
  A: [
    children:[
   {
      reference:"B": [
         children:[
            reference:"C"
         ]
      ]
   }    
  ]
  ........

Please kindly let me know your thoughts
3 years ago
The mail groovy file (MainApp.groovy) has the following code which invokes sample.groovy

script = new GroovyShell(binding).parse(new File("sample.groovy)) script.run()

Log4j.xml has CONSOLE appender with conversion pattern %d{ABSOLUTE} %-5p [%c{1}] %m%n

even by changing to different patterns the line number of the groovy file sample.groovy is not being printed during execution of methods in sample.groovy.

can someone please help me on how to print the lines which is being executed in sample.groovy?

instead of

12:40:57,255 DEBUG [sample] Request:

not it is being printed as

12:40:57,255 DEBUG [MainApp] Request:

so it is being difficult to debug or to know which line is being executed.

Thanks.
4 years ago

Hi,

I would like to know how we can set the encoding scheme for InputStreamReader and ByteArrayOutputScream

I've files where few sentences with the character à

I'm using the below code snippet to convert the file input stream to bytes array

ByteArrayOutputStream stream = new ByteArrayOutputStream();
BufferedReader fileReader = new BufferedReader(new InputStreamReader(inStream));
String line;
while ((line = fileReader.readLine()) != null) {
stream.write(line.getBytes());
stream.write((byte) '\n');
}
return stream.toByteArray();

Later after doing some operations i'm converting the bytes to string as follows

StringBuilder buf = new StringBuilder();
for (int i = 0; i < inFile.length; i++) {
byte b = inFile;
buf.append((char) b);
}
String s = buf.toString().trim();

The final converted string doesn't have the above latin character à

Is there is any way to get the string content along with the character à?

Thanks,
Kathir
7 years ago
Hi,

I'm having XML content as a string. I'm using W3C dom for getting values from the XML.

I've a very large XML file with attributes, elements similar like below

<Shares>
<bookDetails bookName="How to Learn English" bookAuthor="English Writer">
<Chapter chapterName="From Alphabetes" chapterPage="23"/>
</bookDetails>
<company>
<name>test</name>
<address>test address</address>
<contact>test contact</contact>
<C02>10.5</C02>
</company>
</Shares>

Currently I've written a method which accepts Root Element and searchable name to find the corresponding attribute or element and gets the value.

The method will get the value from a element or an attribute matching the given name.

I've used XPathAPI.selectNodeList to retrieve the value. I've used the below XPATH to check the given searchable name in both attribute and in element

xpath = "//*[@" + inAttr + "]";
xpathElement = "//" + inAttr + "/text()";

NodeList nodelist = XPathAPI.selectNodeList(root, xpath);

NodeList nodelist = XPathAPI.selectNodeList(root, xpathElement)

Sample Input and Output as follows

Input: bookName

Output: How to Learn English

Input: address

Output: test address

Input : C02 --> The element name has numeric character too

Output: 10.5

Problem: The XPATHAPI.selectNodeList() causes performance problem and it takes more time to search and gets the value.

I've planned to use regular expression (Pattern, Matcher) to search and get the values from the XML string.

Can anyone please let me know the regular expression with a code snippet to retrieve value either from a element or an attribute
which matches the element or attribute name ???

Thanks,
Kathir

8 years ago
Hi,

I'm having XML content as a string. I'm using W3C dom for getting values from the XML.

I've a very large XML file with attributes, elements similar like below

<Shares>
<bookDetails bookName="How to Learn English" bookAuthor="English Writer">
<Chapter chapterName="From Alphabetes" chapterPage="23"/>
</bookDetails>
<company>
<name>test</name>
<address>test address</address>
<contact>test contact</contact>
<C02>10.5</C02>
</company>
</Shares>

Currently I've written a method which accepts Root Element and searchable name to find the corresponding attribute or element and gets the value.

The method will get the value from a element or an attribute matching the given name.

I've used XPathAPI.selectNodeList to retrieve the value. I've used the below XPATH to check the given searchable name in both attribute and in element

xpath = "//*[@" + inAttr + "]";
xpathElement = "//" + inAttr + "/text()";

NodeList nodelist = XPathAPI.selectNodeList(root, xpath);

NodeList nodelist = XPathAPI.selectNodeList(root, xpathElement)

Sample Input and Output as follows

Input: bookName

Output: How to Learn English

Input: address

Output: test address

Input : C02 --> The element name has numeric character too

Output: 10.5

Problem: The XPATHAPI.selectNodeList() causes performance problem and it takes more time to search and gets the value.

I've planned to use regular expression (Pattern, Matcher) to search and get the values from the XML string.

Can anyone please let me know the regular expression with a code snippet to retrieve value either from a element or an attribute
which matches the element or attribute name ???

Thanks,
Kathir
Hi,

I would like to know the current market salary for 7 years experienced java/j2ee lead?

Which company in chennai offering the best salary?

Please let me know.

Thanks.
9 years ago

Peter i use the below code...

I already did that and it worked fine..but the problem is i need to iterate if it maches for more segments...

For 2 matches, i need to use 2 if statement..what happens if the immediate segments comes with FTX+AAA is more than 10 times...

How to do that without multiple if statements when we get FTX+AAA immediately below???


if(segment.startsWith("FTX+AAA")) {
String ftxSegment2 = st.nextToken().trim();
if(ftxSegment2.startsWith("FTX+AAA")) {
sb.append(segment.substring(0, segment.length()));
String ftxSegment2Desc = ftxSegment2.substring(11, ftxSegment2.length());
sb.append(",");
appendString(sb, ftxSegment2Desc, inDelimiter);
} else {
appendString(sb, segment, inDelimiter);
}
}
9 years ago
Hi,

I'm having a very large string which as below


--------------------------------------------------------------------------------

EQD+CN+SAMPLE18767+2200+++5'
NAD+CA+FIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++GOOD'
FTX+AAA+++ONE'
....
....
EQD+CN+SAMPLE18795+2200+++5'
NAD+CA+TIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++SECOND'
FTX+AAA+++IS FAIR'
....
...
similarly FTX+AAA as above and it goes on


--------------------------------------------------------------------------------

i tokenized each segment with delimiter as ' and able to read each segment.

Now i want to concatenate the FTX+AAA in a single segment if more than one FTX+AAA with IMMEDIATE below

The output is as follows


--------------------------------------------------------------------------------
EQD+CN+SAMPLE18767+2200+++5'
NAD+CA+FIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++GOOD,ONE'
....
....
EQD+CN+SAMPLE18795+2200+++5'
NAD+CA+TIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++SECOND,IS FAIR'
....
...
similarly FTX+AAA should be concatenated if it has similar FTX+AAA IMMEDIATE below.

The FTX+AAA segments can come any number of times immediate below
--------------------------------------------------------------------------------

Please help me how we can do this??? Can anyone help me with the code snippet to do this?

Thanks,
Kathir
9 years ago
Hi,

I may get more than 1000 lines in a file. Each line ends with a new line character. Sometimes the file may have 4 lines.
Other lines will have characters such as , : alone.

I'm storing each line in the database if it is a valid line and If the line contains only the above characters (, : ) i need to skip the line and doesn't want to save.

Example Input,

Allows you to work and play in a secure computing environment.
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Allows you to play online
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Lines Saved:
Allows you to work and play in a secure computing environment.
Allows you to play online

Currently what i'm skipping the line if it has the above characters as below

Pattern.compile([,:+ ])
Matcher matcher = pattern.matcher(string);
String tmp = matcher.replaceAll("")
if(tmp.length > 0 ) {
/// Skip
}

Is there is any other way to do instead of calling replaceAll ??

I like to know whether is there is any other way to check whether the string contains only those characters and nothing else, so that i can directly skip
instead of calling replaceAll and checking for length?

any pattern or regular expression which should say the line contains only those characters and nothing else, so we can skip the line.

Please help.

Thanks,
Kathir
9 years ago

Can you please let me know the Tier-1 product based companies in chennai ??

Also, what are the variable pays the company might offer???
9 years ago
What should be the CTC?

Can you please give me more details on that?

Which are the companies gives more salary as of now?
9 years ago
Hi,

My friend is having 6+ years of Java experience.

How much salary he should get at this time? What is the current market salary in chennai?

Please advise.

Thanks,
Kathir
9 years ago