Store command with InputStream

Friday, 25 December 2015 · 2 messages · last reply 29 Dec 2015
B
buddyonweb-software25 Dec 2015 16:30 #
I am writing a Java program that creates some text data that I want to store as a 'raw' document in a database. In the JavaDocs for the Store command () it states for the constructor public Store(java.lang.String path): "Constructor, specifying a target path. The input needs to be set via Command.setInput(InputStream)." Since the input is not a file, but rather an InputStream of data in memory, I do indeed call setInput. However, I cannot get this to work. Am I doing something wrong? Must the input only be from a file (and not from data in memory)? Here is snippet of code and thanks in advance. Note: Using the client/server mode.
    ClientSession session = new ClientSession(host, port, user, pwd);
    session.open("MyDb");

    String theData =  someFunctionThatReturnsALargeStringOfData();
    ByteArrayInputStream bais = new ByteArrayInputStream(theData.getBytes());

    Store cmd = new Store("newFile.txt");
    cmd.setInput(bais);
session.execute(cmd); session.close(); Note sure if this helps, but this is the stack trace I get. org.basex.core.BaseXException: Stopped at , 1/63: Syntax: STORE (TO [path]) [input] Store raw data.
Stores raw data to the specified [path].
    at org.basex.api.client.ClientSession.receive(ClientSession.java:193)
    at org.basex.api.client.ClientSession.execute(ClientSession.java:162)
    at org.basex.api.client.ClientSession.execute(ClientSession.java:167)
    at org.basex.api.client.Session.execute(Session.java:36)
......
CG
Christian Grün29 Dec 2015 09:19 #
Hi Buddy on Web,
  ClientSession session = new ClientSession(host, port, user, pwd);
  session.open("MyDb");
The open function is unknown to me. Have you added it by yourself, or do you use a ClientSession class different to the one in our project?
Quoted text · buddyonweb-software · 3 lines
> Store cmd = new Store("newFile.txt"); > cmd.setInput(bais); > session.execute(cmd);
The ClientSession.store(...) function from our official source code will do what you want. Christian
Quoted text · buddyonweb-software · 16 lines
> > session.close(); > > > Note sure if this helps, but this is the stack trace I get. > > org.basex.core.BaseXException: Stopped at , 1/63: > Syntax: STORE (TO [path]) [input] > Store raw data. > > Stores raw data to the specified [path]. > at org.basex.api.client.ClientSession.receive(ClientSession.java:193) > at org.basex.api.client.ClientSession.execute(ClientSession.java:162) > at org.basex.api.client.ClientSession.execute(ClientSession.java:167) > at org.basex.api.client.Session.execute(Session.java:36) > ......

⚡Generated with XQuery