Wednesday, June 27, 2007

The much awaited IPHONE

I was so looking forward for this moment.....iphone's release on 29th june. But then, I am going to wait till the first generation is accepted by the market. If you remember what happened with the initial ipods...you'll know what I am talking about. I strongly recommend to all those iphone fans out there to hold off on buying it right away. Interestingly enough apple introduced new features right before the launch - like increased battery life and youtube service. Apple has, over the period learnt how to handle the market - I hope the product cycle for iphone is not as streched as it was for ipods. neways...fingers crossed and hurray once again for the iphone.

Tuesday, April 25, 2006

Posting a document using HttpURLConnection?

Java Programming: Posting a document using HttpURLConnection?: "Posting a document using HttpURLConnection"


----------------------------------------
-----------------
Here is my entire working program
---------------------------------------------------------
import java.io.*;
import java.net.*;

/**
* RFC 1867
* ========
* Content-type: multipart/form-data, boundary=AaB03x
*
* --AaB03x
* content-disposition: form-data; name="field1"
*
* Joe Blow
* --AaB03x
* content-disposition: form-data; name="pics"; filename="file1.txt"
* Content-Type: text/plain
*
* ... contents of file1.txt ...
* --AaB03x--
*/
public class PostDocument {
public static void main(String[] args) throws Exception {
//
// CONSTANTS
//
String url = "http://localhost:8080/Examples/FileLibrary/addFile"; // <--- Zope/Python
// String url = "http://localhost:8080/rcn/jsp/UploadFile.jsp?action=upload"; // <--- Tomcat/JSP
String docPath = "D:\\rcn\\java\\HttpURLConnection\\testdoc.txt";
String bndry = "AaB03x";
String paramName = "file";
String fileName = "testdoc.txt";

//
// CREATE AN HTTP CONNECTION
//
HttpURLConnection httpcon = (HttpURLConnection) ((new URL(url).openConnection()));
httpcon.setDoOutput(true);
httpcon.setUseCaches(false); // ??? Not Required?
httpcon.setRequestMethod("POST");
httpcon.setRequestProperty("Content-type", "multipart/form-data, boundary=" +bndry); // this is new line
httpcon.connect();

//
// OPEN THE READ AND WRITE STREAMS
//
System.out.println("Posting " +docPath +"...");
File file = new File(docPath);
FileInputStream is = new FileInputStream(file);
OutputStream os = httpcon.getOutputStream();

//
// WRITE THE FIRST/START BOUNDARY
//
String disptn = "--" +bndry +"\r\ncontent-disposition: form-data; name=\"" +paramName +"\"; filename=\"" +fileName +"\"\r\nContent-Type: text/plain\r\n\r\n";
System.out.print(disptn);
os.write(disptn.getBytes());

//
// WRITE THE FILE CONTENT
//
byte[] buffer = new byte[4096];
int bytes_read;
while((bytes_read = is.read(buffer)) != -1) {
os.write(buffer, 0, bytes_read);
System.out.print(new String(buffer, 0, bytes_read));
}

//
// WRITE THE CLOSING BOUNDARY
//
String boundar = "\r\n--" +bndry +"--";
System.out.print(boundar);
os.write(boundar.getBytes()); // another 2 new lines

//
// FLUSH / CLOSE THE STREAMS
//
os.flush();
os.close();
is.close();

// DEBUG
System.out.println("\n....Done!!!...\n\n");
dump(httpcon);
}

public static void dump(HttpURLConnection httpcon) throws IOException {
int n=0; // n=0 has no key, and the HTTP return status in the value field
String headerKey;
String headerVal;

while (true){
headerKey = httpcon.getHeaderFieldKey(n);
headerVal = httpcon.getHeaderField(n);

if (headerKey != null || headerVal != null) {
System.out.println(headerKey +": " +headerVal);
}
else {
break;
}

n++;
}

System.out.println();
System.out.println("getRequestMethod : " +httpcon.getRequestMethod());
System.out.println("getResponseCode : " +httpcon.getResponseCode());
System.out.println("getResponseMessage : " +httpcon.getResponseMessage());
}
}

Wednesday, February 15, 2006

Seagate ST1.3 1-Inch Drive: Smaller Yet Holds More Data - Gizmodo

These are nano-mechanics on steroids...boy wat is this world coming to. 1 inch drive is almost as small as a regular sdcard..kewl stuff
Seagate ST1.3 1-Inch Drive: Smaller Yet Holds More Data - Gizmodo

Monday, December 12, 2005

22 MP camera

Waterloo, Ontario, December 1, 2005 - DALSA Corporation (TSX:DSA), an international high performance semiconductor and electronics company, today announced that its customer, Mamiya, has set a shipping date for its new Mamiya ZD medium format camera. The professional grade camera, which integrates DALSA’s 22 million pixel image sensor chip, will be available in Japan on December 21st, 2005, and will be released world-wide in January 2006.

Sunday, December 11, 2005

Theory of Relational Databases by David Maier - E book link

Theory of Relational Databases by David Maier - Ebook link very nice book for relational databases CIS 611 CSU Cleveland State University

Thursday, December 01, 2005

Coffee Boosts Short Term Memory

So if you are attending an important meeting make sure you have a cup of coffee atleast 10-15 mins in advance.

Wednesday, November 30, 2005

Microsoft Vista To Hit By the end of next year

Hope to see major changes in the UI and other features. I already love XP Prof and now Vista might be a better one!

Tuesday, June 28, 2005

Google game

http://www.weavedigital.com/guess-the-google/?l=1

Monday, April 04, 2005

Helicopter Misses

this chopper's driver needed much more training...

sony robots

are robots being designed for this? but looks cool anyway!

face smashed

this is why you should always lock your car's doors

David Blaine beer Revival

he can create anythin from thin air!!!

Basketball Hoopster Girl

this is the best basket made by any player ever

pitstop mishap

i have no idea what happened to the driver

Eager Skydiver

always be patient, or this is what'll happen

Light Bulb Fun

this is what happens when you microwave a bulb

Cool Skating Tricks

now thats called skate boarding!!!

Park Bench Backflip

be more careful if u plan on doin such stunts

what goes up has to come down

this is how reliable old european cars are...