srinivas krishnan

Greenhorn
+ Follow
since Mar 03, 2004
Merit badge: grant badges
For More
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 srinivas krishnan

It is actually required to pass the entire string. The link should appear based on certain condition which is checked-for and if and only if the condition is met, we display the link.Let me know, If there is way to return the string from java code.
Thanks
19 years ago
JSP
I am returning an HTML string from a java method to a jsp(which is basically an href link)For some reason the link does not get resolved and it just prints the text..I escaped the characters < with < > with >> " with "..Any ideas?
Thanks in advance.

Original String:
<a href="test.jsp?row=1&row=2"><img src="/dac/images/pen.gif"></a>
String returned to jsp:<a href="test.jsp?row=1&row=2"><img src="/dac/images/pen.gif"></a>
19 years ago
JSP
Hi mike,
Thanks. Actually i tried \\w and it works too. Just when I thought its looking great..i have a new problem..as we are using jdk131 for the app server..it gave me a No such method error. So I realized the method replaceAll with support to regex is only in jdk141..As such I cannot use this method. We cannot change our env to jdk141 ASAP..Can you suggest an alternative way to solve the problem.
Thanks
20 years ago
Hi Michael,
Thanx. That works. But does it work only for numbers?? It doesnt seem to work If I have a String like
String text = "+x-y+d-e";
thanx again
20 years ago
Hi folks,
I have a string with positive numbers and negative numbers, I am trying to get the positive and negative numbers in two separate ArrayList..and its getting messy..what Is it I am doing wrong..?Can someone suggest a better way.I am first tokenzing based on + and then tokenizing the tokenized string for "-". But the first one in the "-" would be a positive..and I am unable to get that element.
So string like "+1-2-4-8-9+6-4+56";
I need 1,6,56 in one ArrayList and 2,4,8,9,4 in another list. The String always start with + but after that there is no pattern, there could be no - numbers or there could be numerous - numbers. Can someone help me out..?

private void parseNumbers()
{
this.numbers="+1-2-4-8-9+6-4+56";
ArrayList positiveList = new ArrayList();
ArrayList negativeList = new ArrayList();
if (this.numbers !=null && !this.numbers.equalsIgnoreCase(""))
{
StringTokenizer tokenizer = new StringTokenizer(numbers,"+");
while (tokenizer.hasMoreTokens())
{
String numbers = tokenizer.nextToken();
System.out.println("Numbers that start with positive are"+ numbers);
StringTokenizer negNumbers = new StringTokenizer(numbers,"-");
while (negNumbers.hasMoreTokens())
{
String negNumber = ???
}
}
}

}
20 years ago
Thanks for being patient so far :-)
1)Basically, I would like to give a rootPath and jar all the directories and subdirectories(which have files in them)to be included int the jar.When I extract the jar I would like to see the subdirectories too in the jar and not just the files.
2)I would like the user to give the option to specify where he wants the generated jar file to be saved...So how should I use this jarPath to save the jar..? I couldn't find anything in the api..instead of this jar.write(buffer, 0, bytesRead) I want to use the jarPath to save the jar file.
3)I know I have to change the boolean to JarFile but how would I get a reference to the JarFile. jar is object of JarOutputStream in the code.
20 years ago
No actually it doesnt, in some respects..
say i have c:/jartest folder inside which i have
a.txt
b.txt
jartest1(folder) --->has some more files..
1)If I give the path c:/jartest/ as the source for the directorypath I want all the files and folders in that path to be included. cURRENTLY It only does the files and skips the directories in jartest.I know that I have to make a check for isDirectory() and iterate or something like that..but couldn't get it right..so ideally if i open the jar i should have a.txt, b.txt and the folder jartest1 with the files in it.

2)The jar file is automatically created through the FileOutputStream,
but I want to create it at user specified argument jarpath..
jar.write(buffer, 0, bytesRead); How do I change this??

3)I want to return the user a reference to the newly created jar file?
20 years ago
Hi folks,I am trying to create a jar file programatically using the api..I am wondering if some one can help me change the code below to..
1)Include all the files along with the folders and sub-folders found in the directorypath in the jar file.(Currently does only the files found in the directorypath)
2)Write the jarFile created to a specific path.
3)Method should return the jarFile created.

/**
Creates a Jar file from a given directoryPath.
@param jarName is the name of the jar to Create.
@param jarPath is the path where jar has to be created.
@param directoryPath is the path where the files to be jarred are located.
Returns the jar File created.
*/
public boolean createJar(String jarName, String jarPath, String subDirectoryPath)
throws IOException
{
//String jarName = jarName;
boolean status = false;
JarFile finalJarFile = null;
JarOutputStream jar = new JarOutputStream(new FileOutputStream(jarName),new Manifest());
System.out.println(jarName + " created.");
try {
// Allocate a buffer for reading the input files.
byte[] buffer = new byte[1024];
int bytesRead;

File folder = new File(subDirectoryPath);
String fileList[] = folder.list();
// Loop through the file list.
for (int i = 1; i < fileList.length; i ++)
{
// Get the file name.
String fileName = fileList[i];
System.out.println("filename is "+fileName);
try
{
// Open the file.
FileInputStream file = new FileInputStream(subDirectoryPath + fileName);
try
{
// Create a jar entry and add it to the jar.
JarEntry entry = new JarEntry(fileName);
jar.putNextEntry(entry);
// Read the file and write it to the jar.
while ((bytesRead = file.read(buffer)) != -1)
{
jar.write(buffer, 0, bytesRead);
}
System.out.println(entry.getName() + " added.");
}
catch (Exception ex)
{
System.out.println(ex);
}
finally
{
file.close();
}
}
catch (IOException ex)
{
System.out.println(ex);
}
}
}
finally {
jar.close();
status = true;
System.out.println(jarName + " closed.");
}
return status;
}
20 years ago
Hi Joesph,
Thanks for the response. Actually I am planning ahead of time. I may have a dbresult of 30,000 rows for ex..which I may want to write to a text file or construct a string with 30,000 lines and return it. If I am doing soemthing like..
for(int i=0;i<rs.resultSize();i++)
{
sbuf.append(rs.getObjectAt(i,fieldname));
sbuf.append(delimiter);
}
sbuf.append("\n");
It is gonna be a big time/memory operation..to create the sbuf..am I wrong?
20 years ago
Hi All,
I am wondering how flush works in java..I am constructing a big string from a DB result object using a StringBuffer. Since I don't want to keep the big string in memory I would like to keep flushing it once in a while..while I am constructing it..
I need to have the final String written to a file in some cases and also return just as a String in some cases.Can Any one provide any insight..if possible with some code.
Thanks
20 years ago
Hi All,
I am wondering how flush works in java..I am constructing a big string from a DB result object using a StringBuffer. Since I don't want to keep the big string in memory I would like to keep flushing it once in a while..while I am constructing it..
I need to have the final String written to a file in some cases and also return just as a String in some cases.Can Any one provide any insight..if possible with some code.
Thanks
20 years ago
Actually the ex I mentioned is not right..here is the sample xml
<rootElement>
<a></a>
<b></b>
<x>
<y>
<z></z>
</y>
</x>
</rootElement>
I am trying to parse for an element which could be at any level inside an xml schema and return just the parents of that element using JDOM. I started the code but could not finish it..Could some one help me with the code..
for ex:
<rootElement>
<a>
<b>
<x>
<y>
<z></z>
</y>
</x>
</b>
</a>
</rootElement>
I have a method where I pass the element name z as an argument and I wish to get back the xml below(just the parents of the element I am looking for)
..note that elements a and b are skipped.
<rootElement>
<x>
<y>
<z></z>
</y>
</x>
</rootElement>

private void parseschema( String elementName, String schemafilename) throws IOException {
boolean hasNoChildren=false;
SAXBuilder builder = new SAXBuilder();
try {
Document schemaDoc = builder.build(schemafilename);
List elements = schemaDoc.getRootElement().getChildren();
if ( elements.size()==0 ) {
hasNoChildren=true;
//throw an exception.
}
else
{
Iterator iElts = elements.iterator();
while (iElts.hasNext()) {
Element currElt = (Element) iElts.next();
String eleName = currElt .getName();
if (eleName.equals(elementName))
{
//match
}
else
{
//continue descent until match and return only the parents of the element passed.
}
}
}
} catch (JDOMException e) {
throw new IOException(e.getMessage());
}
}