Hallo,
ich versuche mich derzeit an XMP Metadatenverarbeitung. Da diese für Java leider nur sehr bedingt Dokumentiert ist (für C++ übrigens um Welten besser!), steige ich da in vielen Dingen noch nicht so wirklich durch.
Nach langem forsten konnte ich einen Java XMPDumper auftreiben der leider nicht funktioniert... ;-(
Das if-statement "if (i==0xFF && is.read()==0xE1))" tritt in dem Snippet leider nie ein und somit ist die Ausgabe immer null.
[Java]
public class XMPDumper {
public static void main(String[] args) throws IOException {
File f = new File("d:/test.jpg");
String xmp = new XMPDumper().getXMP(f);
System.out.println(xmp);
}
public String getXMP(File f) throws IOException {
FileInputStream is = new FileInputStream(f);
int i=0;
String result=null;
while ((i=is.read()) != -1){
if (i==0xFF && is.read()==0xE1) {
result = checkNamespace(is);
if (result!=null) break;
}
}
return result;
}
public static final String namespace =
"http://ns.adobe.com/xap/1.0/";
private String checkNamespace(FileInputStream is)
throws IOException {
String s = getSegment(is);
System.out.println("Hier"+s);
return (s.startsWith(namespace)) ? s.substring(29) : null;
}
private String getSegment(InputStream is)
throws IOException {
DataInputStream dis = new DataInputStream(is);
byte[] buffer = new byte[dis.readShort()-2];
dis.read(buffer);
return new String(buffer);
}
}
[/code]
Ich hoffe hier kann mir jemand weiterhelfen.
Vielen Dank im Voraus!
geneticZ
ich versuche mich derzeit an XMP Metadatenverarbeitung. Da diese für Java leider nur sehr bedingt Dokumentiert ist (für C++ übrigens um Welten besser!), steige ich da in vielen Dingen noch nicht so wirklich durch.
Nach langem forsten konnte ich einen Java XMPDumper auftreiben der leider nicht funktioniert... ;-(
Das if-statement "if (i==0xFF && is.read()==0xE1))" tritt in dem Snippet leider nie ein und somit ist die Ausgabe immer null.
[Java]
public class XMPDumper {
public static void main(String[] args) throws IOException {
File f = new File("d:/test.jpg");
String xmp = new XMPDumper().getXMP(f);
System.out.println(xmp);
}
public String getXMP(File f) throws IOException {
FileInputStream is = new FileInputStream(f);
int i=0;
String result=null;
while ((i=is.read()) != -1){
if (i==0xFF && is.read()==0xE1) {
result = checkNamespace(is);
if (result!=null) break;
}
}
return result;
}
public static final String namespace =
"http://ns.adobe.com/xap/1.0/";
private String checkNamespace(FileInputStream is)
throws IOException {
String s = getSegment(is);
System.out.println("Hier"+s);
return (s.startsWith(namespace)) ? s.substring(29) : null;
}
private String getSegment(InputStream is)
throws IOException {
DataInputStream dis = new DataInputStream(is);
byte[] buffer = new byte[dis.readShort()-2];
dis.read(buffer);
return new String(buffer);
}
}
[/code]
Ich hoffe hier kann mir jemand weiterhelfen.
Vielen Dank im Voraus!
geneticZ