• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Problem with save data in XML format

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have to save our data in XML format I am getting data but unable to save it something is going wrong..

Problem in following code

JNLPProxy.saveAsLocalFile(bio, "export.xml");




where bio is ByteArrayInputStream which containing data..
and JNLPProxy class is


public final class JNLPProxy
{

private static final Object basicServiceObject = getBasicServiceObject();
private static final Class basicServiceClass = getBasicServiceClass();
private static final Object fileOpenServiceObject = getFileOpenServiceObject();
private static final Class fileOpenServiceClass = getFileOpenServiceClass();
private static final Object fileSaveServiceObject = getFileSaveServiceObject();
private static final Class fileSaveServiceClass = getFileSaveServiceClass();

public static void main(String[] args) throws Exception{
showDocument(new URL(args[0]));
}

public static boolean showDocument(URL url){
if (basicServiceObject == null) {
return false;
}

try {
Method method = basicServiceClass.getMethod("showDocument",
new Class[] { URL.class });
Boolean resultBoolean = (Boolean) method.invoke(basicServiceObject,
new Object[] { url });
return resultBoolean.booleanValue();

} catch (Exception ex) {
ex.printStackTrace();

throw new RuntimeException(ex.getMessage());
}
}

public static URL getCodeBase(){
if (basicServiceObject == null) {
return null;
}

try {
Method method = basicServiceClass.getMethod("getCodeBase", null);
URL url = (URL) method.invoke(basicServiceObject, null);
return url;

} catch (Exception ex) {
ex.printStackTrace();

throw new RuntimeException(ex.getMessage());
}
}


private static Object getBasicServiceObject() {
try {
/*Class serviceManagerClass = Class
.forName("javax.jnlp.ServiceManager"); *///here change required @Vaibhav

Class serviceManagerClass = Class.forName("javax.jnlp.ServiceManagerStub");
Method lookupMethod = serviceManagerClass.getMethod("lookup",
new Class[] { String.class });

return lookupMethod.invoke(null,
new Object[] { "javax.jnlp.BasicService" });
} catch (Exception ex) {
return null;
}
}

private static Class getBasicServiceClass() {
try {
return Class.forName("javax.jnlp.BasicService");
} catch (Exception ex) {
return null;
}
}
private static Object getFileOpenServiceObject() {
try {
Class serviceManagerClass = Class
.forName("javax.jnlp.ServiceManager");

Method lookupMethod = serviceManagerClass.getMethod("lookup",
new Class[] { String.class });

return lookupMethod.invoke(null,
new Object[] { "javax.jnlp.FileOpenService" });
} catch (Exception ex) {
return null;
}
}

private static Class getFileOpenServiceClass() {
try {
return Class.forName("javax.jnlp.FileOpenService");
} catch (Exception ex) {
return null;
}
}
private static Object getFileSaveServiceObject() {
try {
Class serviceManagerClass = Class.forName("javax.jnlp.ServiceManager");

Method lookupMethod = serviceManagerClass.getMethod("lookup",
new Class[] { String.class });

return lookupMethod.invoke(null,
new Object[] { "javax.jnlp.FileSaveService" });
} catch (Exception ex) {
return null;
}
}

private static Class getFileSaveServiceClass() {
try {
return Class.forName("javax.jnlp.FileSaveService");
} catch (Exception ex) {
return null;
}
}

public static boolean saveAsLocalFile(InputStream is, String fileName) {
if (fileSaveServiceObject == null) {
return false;
}

try {
Method method = fileSaveServiceClass.getMethod("saveFileDialog",
new Class[] { String.class, String[].class, InputStream.class, String.class});
method.invoke(fileSaveServiceObject,
new Object[] {null, null, is, fileName});
return true;

} catch (Exception ex) {
ex.printStackTrace();

throw new RuntimeException(ex.getMessage());
}
}
private JNLPProxy() {
}
}



But it is not working and returning null�plz give me the appropriate advice where the problem is...

Thanks
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic