sathish

Ranch Hand
+ Follow
since Apr 25, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by sathish

hi bosun
i checked the API, but i just want to know the table name before the execution of query, but still, when i run through the query, i can't get the table name through the resultsetmetadata.
Does the method getTableName() get me the table name?? but i got null.
Thanks
sathish
Does anyone j=know how to get a table name from a query?
like Select * from Employ... i want to get the table name. Kindly help
Thanks
sathish
XSU
Hello Everyone
I get an exception when using Oracle XSU for Non-oracle driver & non-oracle database(SQL Server 7.0)
The exception is "oracle.xml.sql.OracleXMLSQLException" I just wanted to know whether this product will work only with Oracle database/Oracle driver or will work for other databases too.
Thanks
sathish
Can anyone advise me on the MD5 algorithm to identify the changed files in a directory? or how to use the algorithm in java?
24 years ago
Hi Asad ali
Thanks for your reply, but when you comment out the res.setbuffersize line from the doPost method, the first time it executes doesn't work, however, can you try sending files of the size 5.00MB ++?
And, if you keep sending files repeatedly, it fails to respond, and i have also submitted it to the sun developer site.
Thanks for your reply
sathish
24 years ago
Is any one out there to help me???
thanks
24 years ago
the problem occurs when
A(Client) ------> Establishes a HttpUrlConnection ---->B(Server)
B(Server) -----> Receives the request and sends back ----> A(Client) --->Timeout occurs and not able to send the contents..
Why?
Is that related to the file size???
Please help
Thanks
sathish
24 years ago
Hi guys
Having problems sending files greater than 4MB through my program, it is not able to send it. It looks like the server receive the correct file, but the contents are not going through
Attached below is the file
Server(Testconn) and client-(Httptest)
Please help
Thanks
sathish
______________________________________________________________
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.zip.ZipFile;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class HttpTest extends Frame implements ActionListener
{
ZipFile zip = null;
java.awt.List list = null;
//The zip file name.
String filename = null;
MenuItem mOpen, mQuit;
public static void main(String args[])
{
new HttpTest();
}
public HttpTest()
{
setTitle("UnZip Tool");

setLayout(new BorderLayout(3, 3));
add(new Label("Http URL Test: Open a jar/zip file, it will visit your Servlet and go back."),
"North");
list = new java.awt.List(20, true);
add(list, "Center");
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu mFile = new Menu("File");
mb.add(mFile);
mOpen = new MenuItem ("Open", new MenuShortcut('O'));
mFile.add(mOpen);
mFile.addSeparator();
mQuit = new MenuItem("Quit", new MenuShortcut('Q'));
mFile.add(mQuit);
mOpen.addActionListener(this);
mQuit.addActionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { quit(); }
});
setBounds(100,100, 400, 600);
show();
}
void open()
{
FileDialog f = new FileDialog(this, "Open a Zip File",
FileDialog.LOAD);
f.show();

if(f.getFile() == null)
{
return;
}
try
{
filename = new File(f.getDirectory(), f.getFile()).getAbsolutePath();
//FileInputStream fis = new FileInputStream(filename);
//ZipInputStream zis = new ZipInputStream(fis);
zip = new HTTPComu(new File(filename)).getZipFile();
list.removeAll();
ZipEntry entry;
if (zip == null) {
return;
}

Enumeration enum = zip.entries();
while(enum.hasMoreElements()) {
entry = (ZipEntry)(enum.nextElement());
if(!entry.isDirectory()) {
list.add(entry.getName());
}
}
}
catch(Exception e)
{
System.out.println("Error: Can't open zip file " + f.getFile());
e.printStackTrace();
}
}
void quit()
{
System.exit(0);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == mOpen) open();
else if (source == mQuit) quit();
}
}
class HTTPComu {
File input = null;
String outputFile = null;
public ZipFile getZipFile() {
if (outputFile == null) {
return null;
}
try {
return new ZipFile(outputFile);
} catch (Exception e) {
return null;
}


}

private String name = "Fred's test HTTP Connector!";
private Hashtable hash = new Hashtable();

public HTTPComu(File zip) {
try {
input = zip;

hash.put("hello", " helloValue ....");
hash.put("hello!", "Christmas");
/*
Properties props = new Properties();
FileInputStream in = new FileInputStream("PostTest.properties");
prps.load(in);
props.remove("URL");
*/

URL url = new URL("http://ferret:80/servlet/TestCon");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
send(connection);
receive(connection);
connection.disconnect();
//output = input;
} catch (Exception e) {
System.out.println("Error: " + e);
e.printStackTrace();
}
}

private void send(HttpURLConnection connection) {

try {
String contentType = "application/x-www-form-upload";
connection.setRequestProperty("Content-Type", contentType);
connection.setRequestProperty("Connection", "keep-alive");
connection.setRequestMethod("POST");
ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream());
out.writeObject(name);
out.writeObject(hash);
System.out.println("Sent hash table:\n" + hash);
FileInputStream in = new FileInputStream(input);
byte[] data = getFileData(in);
in.close();
out.writeObject(data);
System.out.println("Sending finished!");
out.flush();
out.close();
} catch (Exception e) {
System.out.println("Sedning error : " + e);
}
}
private void receive(HttpURLConnection connection) throws Exception {
try {
//HttpURLConnection.HTTP_CLIENT_TIMEOUT = 4096;
System.out.println("Receiving starts!");
System.out.println("Type: " + connection.getContentType() +
"\tLength: " + connection.getContentLength() +
"\tEncoding: " + connection.getContentEncoding());

ObjectInputStream in = new ObjectInputStream(connection.getInputStream());
System.out.println("Receiving going !");
File output = File.createTempFile("http", ".zip");
outputFile = output.getPath();
output.deleteOnExit();
System.out.println("Create tmp file " + output);
FileOutputStream fileout = new FileOutputStream(output);
Object obj;
obj = in.readObject();
hash = (Hashtable)obj;
System.out.println("Returned hash table:\n" + hash);
obj = in.readObject();
byte[] data = (byte[])obj;
fileout.write(data, 0, data.length);
fileout.close();
in.close();
System.out.println("Receiving finished! " + data.length);
} catch (Exception e) {
System.out.println("Receive error: " + e);
e.printStackTrace();
}
}
public byte[] getFileData(InputStream in)
throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
int size = 2048;
byte data[] = new byte[size];
int readedSize;
long count = 0;
while((readedSize = in.read(data, 0, size)) != -1) {
out.write(data, 0, readedSize);
count += readedSize;
}
System.out.println("Reading file! " + count);

out.close();

return out.toByteArray();
}
}
-----------------------------------------------------------------
import java.io.*;
import java.util.*;
import java.util.zip.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class TestCon extends HttpServlet {
File output = null;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
System.out.println("Do Get in the Echo!");
//doPost(req, res);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.print("<html>");
out.print("<head><title>Hello World3</title></head>");
out.print("<body>");
out.print("<h1>Hello World" + new Date() + "</h1>");
System.out.println("TestCon doGet!");
out.print("</body></html>");

}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
ZipFile zip;
String name;
Hashtable hash;
Object obj;

try {
//ByteArrayOutputStream buffer = new ByteArrayOutputStream();
res.setContentType("text/html");
ObjectInputStream in = new ObjectInputStream(req.getInputStream());

System.out.println("TestCon doPost!");

obj = in.readObject();
name = (String) obj;

obj = in.readObject();
hash = (Hashtable) obj;

output = File.createTempFile("http", ".zip");
output.deleteOnExit();
System.out.println("Create tmp file " + output);

FileOutputStream fileout = new FileOutputStream(output);
obj = in.readObject();
byte[] data = (byte[]) obj;
fileout.write(data, 0, data.length);
System.out.println("Reading Finished! " + data.length);

fileout.close();

//in.close();
System.out.println("Name " + name);
System.out.println("Hash " + hash);
//System.out.println("Length " + length);

////Send back
//ObjectOutputStream out = new ObjectOutputStream(buffer);

res.setBufferSize(data.length + 10240);
ObjectOutputStream out = new ObjectOutputStream(res.getOutputStream());
out.writeObject(hash);
System.out.println("Start to sending back!");
//FileInputStream filein = new FileInputStream(output);
//data = getFileData(filein);
//filein.close();
out.writeObject(data);
System.out.println("Writing data!");
//res.setBufferSize(buffer.size() + 1024);
//res.setContentLength(buffer.size());
out.close();
System.out.println("Sending back finished!" + data.length);
} catch (Exception e) {
System.out.println("Reading data error " + e);
e.printStackTrace();
}
}
public byte[] getFileData(InputStream in)
throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
int size = 2048;
byte data[] = new byte[size];
int readedSize;
long count = 0;
while((readedSize = in.read(data, 0, size)) != -1) {
out.write(data, 0, readedSize);
count += readedSize;
}
System.out.println("\tReading file ! " + count);

out.close();

return out.toByteArray();
}
public String getServletInfo() {
return "Echo what it gets from client";
}
}
24 years ago
I have a Servlet application sending zip files to the client the servlet is not able to send files of size greater than 5 MB to the client.
Is that the maximum size of data i can send through a stream?
thanks
sathish
24 years ago
Hello Everyone
I have a file/folder which needs to be monitored for period of time. How can i check to see if the new files have been added or deleted or changed in the directory? can i use XML with java to take a snap shot of the file and compare when it changes? if so how do you do it?
thanks
sathish
24 years ago
uma
i thought you were asking to convert to decimal, Ok it's again simple
Much simple
Write the Hexadecimal digit or alphabet as it's 4-digit binary equivalent.
e.g 0x0012
0000 0000 0001 0010 and you get 18.
sathish
hi uma
A short solution.
first take the positional values for the one you are converting
for e.g: a Hexadecimal can have 4096, 256, 16, 1 and then identify the exact decimal equivalent of the number or character from the Decimal- Hexadecimal representation chart..( you know from 0 to 9 the numbers are the same in Hexadecimal and 10-A, 11-B, 12-C, 13-D, 14-E, 15-F)assign & multiply with the Postional values. Finally add all those and you will get the decimal equivalent.
eg: 0x0012 equivalent to 18. ( 1 * 16 + 2 * 1)
i found this to be quick and hope this is of use to you
Sathish
Mani..
In my view, there are only three states where a thread can be stopped.
1. stop() method (jdk1.1) which is now deprecated.
(or)
when a interrupt method is called on a thread, the thread breaks out of a sleep() or wait() and a interrupted exception is thrown
to be more clear, When the interrupt method is called on a thread object that is currently blocked, the blocking call (such as sleep or wait) is terminated by an interrupted exception.
But there is no Hard and Fast rule or no language requirement that a thread that is interrupted should end or terminate!
There are several instances where in some threads which are really important that they might simply ignore their interruption by catching the exception and would continue!. But mostly, a thread will simply interrupt an interruption as a request for termination.
2. Threads which are blocked or in a blocked state are said to be temporarily stopped ( Sleep, wait or even if a thread is waiting for an object lock that is owned by another thread, then the other thread must have given up the lock, or a thread which waits for an IO operation such as read())
3.when a higher priority thread is available.( i would say runnable and not available)
A higher priority thread is runnable or only runnable until it relinquishes by a yield() or till it naturally ceases to be runnable and this may be by entering a blocked state or when another thread with a higher priority becomes runnable.
i hope this is clear for you.
correct me if i am wrong!
thanks
sathish
jvarkha..
sorry -- " since i took the test very recently"
sathish