Friday, May 11, 2007

Stupidity knows no bounds!


I am speechless. I am not even sure where to begin addressing this. Someone at Vancouver International Airport actually convinced others to get a budget for a project to tell people how to bring food on an airplane. They developed a small logo for their project. Do they really think we need signs to help us? Did they envision that people are too clueless to figure the three steps out for themselves (1. buy food; 2. ask for it "to go", 3. bring it on plane)??? WTF??? These signs are everywhere.

This is one project I am glad I was not in any meetings for. I would have strangled someone.

Duane's World 2007 Java One "Coolest in Show" award

Every year I blog after Java One and recognize one company, demo, entry, exhibit that is better than all others. In 2006, this award went to a robotic Lego and Java demonstration. This is never an easy task since there are so many cool things at Java One. This year is no easier. After much internal debate and watching the "wow" factor from peopel seeing things for the first time, I bestow the 2007 Duane's World "Best in Show" award to the Java powered helicopter. Das ist ein sehr gute Hubschrauber!



Runners up were the Sun SPOT (Small Programmable Object Technology) and the Quebec University students Java submarine. the latter failed to make tops given they have not yet included an adaptive algorithm to learn and re-program thrust bursts based on Causality Event Programming models (The thrusters usually over-compensated in attempts to level the device). While it is not "kinderspiele" (Child's play), it could be done with minimal effort. Quebec has a long history of great technology and good hockey goalies so I look forward to seeing what they bring next year.

Disclaimer: I excluded the Flex, Apollo and Java PDF code from Adobe.

Thursday, May 10, 2007

Java One 2007 source code and slides

Java One 2007 is full on! My favorite was the helicopter but I also can't wait to start developing with the SunSpot devices. I think I am going to build a solar tracking device.

Anyways - thanks to all of you who came to my talk. I was overwhelmed with the great reception and applause and felt really humble to be appreciated by such an esteemed and knowledgable peer group. I don't use Java every day so I was happy to see all the code I wrote for you compile the first time. Felt like I dodged a bullet.

Here is the first class (DuanePDFClass2.java). You will need to download the XPAAJ.jar file to make this work. The other class is directly below. You should also know that we are moving towards the XML friendly version of PDF ("Mars") which will allow any developer to work with PDF XML formats using the XML parser in their native language. For the long term, this is a much better solution than us developing libraries for each and every programming language.

import java.io.*;
import java.util.*;
import java.awt.image.DataBuffer;
import com.adobe.pdf.*;

public class DuanePDFClass2 {
public static void main(String[] args)
throws FileNotFoundException, IOException

/* Make sure we have the correct args.length() and call PDFExtract() */

{
String inPdfName;
if(args.length != 1 )
{
System.out.println("\nCommand line format: java classname pdf-file");
return;
}
else
{
inPdfName = new String(args[0]);
PDFExtract(inPdfName);
}
}

public static void PDFExtract(String inPdfName)
throws FileNotFoundException, IOException
{
System.out.println("\nOpening PDF with DuanePDFClass2...");
PDFDocument doc = null;
boolean b = false;
FileInputStream inPdfFile = new FileInputStream(inPdfName);
try {
doc = PDFFactory.openDocument(inPdfFile);
} catch (IOException e) {
System.out.println("Error opening PDF file :" + inPdfName);
System.out.println(e);
}
if(doc == null)
System.out.println("Cannot open PDF file : " + inPdfName);
else
System.out.println( inPdfName + " was successfully opened.");

System.out.println ("Document Version = " + doc.getVersion());

System.out.println ("PDF is " + doc.getNumberOfPages() + " pages long.");

/*Save PDF to file*/
System.out.println ("\nSaving document ... ");
int j = inPdfName.lastIndexOf(".");
String outPdfName = inPdfName.substring(0, j) + "_saved_by_Duane_at_JavaOne2007" + ".pdf";

InputStream inputStream;
inputStream = doc.save();
b = false;
try {
b = saveFile(inputStream, outPdfName);
} catch (Exception e) {
System.out.println("Error saving PDF file.");
System.out.println(e);
}
if(b == true)
System.out.println ("Document was saved to file : " + outPdfName);
else
System.out.println("Document was not saved to file.");

System.out.println("\nExecution of DuanePDFClass1 has finished.");
}
/**
method to save InputStream to a file.
*/
public static boolean saveFile(InputStream is, String filePath)
throws Exception
{
boolean retVal=false;
byte[] buffer = new byte[10240];
FileOutputStream outStream = null;
try
{
outStream = new FileOutputStream(filePath);
int len=0;
while (true)
{
len = is.read(buffer);
if (len == -1)
break;
outStream.write(buffer, 0, len);
}
outStream.close();
retVal = true;
}
catch (IOException io)
{
System.out.println("Writing the array of bytes into the file "
+ filePath + " failed.");
throw new Exception(
"Writing the array of bytes into the file "+ filePath +
" failed in saveFile");
}
return retVal;
}
}


Here is the second class which casts the input stream handed off by the Document factory class into a buffered stream reader and strips out the XMP metadata.

import java.io.*;
import java.util.*;
import java.awt.image.DataBuffer;
import com.adobe.pdf.*;

/* XMPExtractSample
* by Duane Nickull, Adobe Systems Inc. dnickull@adobe.com
* Copyright (c) October 25, 2006 - all rights reserved
*
* Use this at your own risk and don't whine/winge on to me if it doesn't work.
* You will need to have XPAAJ.jar from Adobe labs.
* Written and tested with JDK 1.5 on a mac w/osx 10.4.7

*/

public class XMPExtractSample {
public static void main(String[] args)
throws FileNotFoundException, IOException

/* Make sure we have the correct args.length() and call PDFExtract() */
{
String inPdfName;
if(args.length != 1 )
{
System.out.println("\nCommand line format: java DuanePDFClass1 pdf-file");
return;
}
else
{
inPdfName = new String(args[0]);
PDFExtract(inPdfName);
}
}

public static void PDFExtract(String inPdfName)
throws FileNotFoundException, IOException
{
System.out.println("\nOpening PDF with DuanePDFClass1...");
PDFDocument doc = null;
boolean b = false;
FileInputStream inPdfFile = new FileInputStream(inPdfName);
try {
doc = PDFFactory.openDocument(inPdfFile);
} catch (IOException e) {
System.out.println("Error opening PDF file :" + inPdfName);
System.out.println(e);
}
if(doc == null)
System.out.println("Cannot open PDF file : " + inPdfName);
else
System.out.println( "\n" + inPdfName + " was successfully opened.");

// Export the xmp metadata from the document
try {

//Call the PDFDocument object's exportXMP method.
InputStream myXMPStream = doc.exportXMP();

//Get the byte size of the InputStream object.
int numBytes = myXMPStream.available();
System.out.println("\nNumber of XMP Bytes found is " + numBytes + "\n");

// Read into a Buffered Reader Stream.
BufferedReader d = new BufferedReader(new InputStreamReader(myXMPStream));

// Iterate through the XMP object and print each line
String xmpLine;
while((xmpLine = d.readLine()) != null)
{
System.out.println(xmpLine);
}
// Find the Physical Memory Reference of the object
System.out.println("\nXMP InputStream is in physical memory at -> " + d);

//Create an array of bytes. Allocate numBytes of memory.
byte [] MDBytes = new byte[numBytes];

//Read the XMP metadata by calling the InputStream object’s read method.
myXMPStream.read(MDBytes);
} catch (IOException e){
System.out.println("it went really bad" + e );
}
System.out.println("\nXMP Extraction has finished.");
}
}