how to store byte array in neo4j database - neo4j

I am unable to create a node in neo4j database to store byte array through java code. Please can anybody help?
String q = "create(userImage:UserImage{imageBytess:'"+imageBytes+"'})";
This stores as String. I am not getting how to do for bytes

Have you try this :
// Given
byte[] byteArray = "hello, world".getBytes();
// When
StatementResult result = session.run("CREATE (a {value:{value}}) RETURN a.value", parameters( "value", byteArray ) );

Related

Can you append an integer onto a Buffer without converting to a string?

The only DXL documentation I've found suggests converting to a string
Buffer buf = create()
int i = 2
string str = i ""
buf = str
Is there a way to skip creating the string and go directly to the Buffer?
No, unless you take
int i = 2
buf += i""
as a solution. Which is basically the same as you do, just without creating an additional variable

convert a String of "uint8list" to a Unit8List

I have a memory image stored in Sqllite converted to String with the toString() method, I want to convert it to Unit8List to display it inside a MemoryImage widget
codeUnits gets you a List<int>
Uint8List.fromList(...) converts List<int> to Uint8List
String.fromCharCodes(...) converts List<int> or Uint8List to String
List<int> list = 'xxx'.codeUnits;
Uint8List bytes = Uint8List.fromList(list);
String string = String.fromCharCodes(bytes);
Use utf8.encode(myString) to convert String to bytes or List<int>,
And then convert it back using utf8.decode(bytes)
String source = 'BÅ‚onie';
List<int> list = utf8.encode(source);
Uint8List bytes = Uint8List.fromList(list);
String outcome = utf8.decode(bytes);
the best and simple way of doing it is,
Image.memory(base64decode(string_value_here))

Sequence contains no elements - PayPal SOAP Response

I am trying to read the value from an XML element but I always get "Sequence contains to elements" error.
I already done my research but nothing works for my problem.
I want to read the Ack and Timestamp element values in this XML
<DoDirectPaymentResponse xmlns="urn:ebay:api:PayPalAPI">
<Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2014-09-16T04:41:56Z</Timestamp>
<Ack xmlns="urn:ebay:apis:eBLBaseComponents">Success</Ack>
</DoDirectPaymentResponse>
Here's my code for reading the Ack and Timestamp values
String xmlString = #xml;
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
XDocument xdoc = XDocument.Load(reader);
var timestamp = xdoc.Descendants("Timestamp").Single();
receipt.Timestamp = timestamp.Value;
var response = xdoc.Descendants("Ack").Single();
receipt.Response = response.Value;
}
Please help me with this. Thanks a lot.
You need to use proper XNamespace to access elements in the namespace :
XDocument xdoc = XDocument.Parse(xmlString);
XNamespace ns = "urn:ebay:apis:eBLBaseComponents";
var timestamp = xdoc.Descendants(ns+"Timestamp").Single();
receipt.Timestamp = timestamp.Value;
var response = xdoc.Descendants(ns+"Ack").Single();
receipt.Response = response.Value;
Side note: you can use XDocument.Parse() to load XML from XML string content.

Titanium ByteArray to image Blob

I have a list of images encoded as ByteArrays from an API to be displayed in a TableView
Here is one of the ByteArrays
i'm not managing to display an image with it,
nor saving a file or making a buffer or a stream buffer, those are some examples
var blobStream = Ti.Stream.createStream({ source: array, mode: Ti.Stream.MODE_READ });
or
var buff = Ti.createBuffer({value:array, length:array.length, type:Ti.Codec.CHARSET_UTF8});
and giving the array either to
Titanium.Utils.base64decode( array );
Titanium.Utils.base64encode( array );
crashes badly with "wrong type passed to function"
How can I make a blob out of a ByteArray and set it to an Imageview?
You can use this snippet to convert byte array in base64 string.
Decode the string with var imageBlob = Ti.Utils.base64decode(string);
and than set it in var image = Ti.UI.createImageView({ image:imageBlob });

How can I convert bytearray to String

I am extracting metadata of a song using following code ,And how I can convert the byte array (buf) to string? Please help me,Thanks in advance.
String mint = httpConnection.getHeaderField("icy-metaint");
int b = 0;
int count =0;
while(count++ < length){
b = inputStream.read();
}
int metalength = ((int)b)*16;
if(metalength <= 0)
return;
byte buf[] = new byte[metalength];
inputStream.read(buf,0,buf.length);
1). Read bytes from the stream:
// use net.rim.device.api.io.IOUtilities
byte[] data = IOUtilities.streamToBytes(inputStream);
2). Create a String from the bytes:
String s = new String(data, "UTF-8");
This implies you know the encoding the text data was encoded with before sending from the server. In the example right above the encoding is UTF-8. BlackBerry supports the following character encodings:
* "ISO-8859-1"
* "UTF-8"
* "UTF-16BE"
* "US-ASCII"
The default encoding is "ISO-8859-1". So when you use String(byte[] data) constructor it is the same as String(byte[] data, "ISO-8859-1").
If you don't know what encoding the server uses then I'd recommend to try UTF-8 first, because by now it has almost become a default one for servers. Also note the server may send the encoding via an http header, so you can extract it from the response. However I saw a lot of servers which put "UTF-8" into the header while actually use ISO-8859-1 or even ASCII for the data encoding.
String has a constructor that accepts a byte array that you can use for this.
See e.g. http://java.sun.com/javame/reference/apis/jsr139/java/lang/String.html
As #Heiko mentioned you can create string directly using the constructor. This applies to blackberry java too:
byte[] array = {1,2,3,4,5};
String str = new String(array);

Resources