binary-data

Sending binary data with HttpURLConnection

[亡魂溺海] 提交于 2019-12-07 22:57:05
问题 i want to use google speech api, i've found this https://github.com/gillesdemey/google-speech-v2/ where everything is explained well, but and im trying to rewrite it into java. File filetosend = new File(path); byte[] bytearray = Files.readAllBytes(filetosend); URL url = new URL("https://www.google.com/speech-api/v2/recognize?output="+outputtype+"&lang="+lang+"&key="+key); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //method conn.setRequestMethod("POST"); //header conn

Identifying the type of a file without extension from binary data

独自空忆成欢 提交于 2019-12-07 17:58:39
问题 I have some files without extension. I would like associate extensions to them. For that I have written a python program to read the data in the file. My doubt is how can I identify its type without the extension without using third party tools. I have to identify a pdf, doc and text file only. Other type of files are not possible. My server is cent os 回答1: You could read the first few bytes of the file and look for a "magic number". The Wikipedia page on magic numbers suggests that PDF files

Invoking a function (main()) from a binary file in C

∥☆過路亽.° 提交于 2019-12-07 11:40:49
问题 I have simple c program like, my_bin.c: #include <stdio.h> int main() { printf("Success!\n"); return 0; } I compile it with gcc and got executable: my_bin. Now I want to invoke main (or run this my_bin) using another C program. That I did with mmap and function pointer like this: #include <stdio.h> #include <fcntl.h> #include <sys/mman.h> int main() { void (*fun)(); int fd; int *map; fd = open("./my_bin", O_RDONLY); map = mmap(0, 8378, PROT_READ, MAP_SHARED, fd, 0); fun = map; fun(); return 0

Inserters and Extractors reading/writing binary data vs text

泄露秘密 提交于 2019-12-07 04:01:14
问题 I've been trying to read up on iostreams and understand them better. Occasionally I find it stressed that inserters ( << ) and extractors ( >> ) are meant to be used in textual serialization. It's a few places, but this article is a good example: http://spec.winprog.org/streams/ Outside of the <iostream> universe, there are cases where the << and >> are used in a stream-like way yet do not obey any textual convention. For instance, they write binary encoded data when used by Qt's QDataStream

Serving binary files from the database with compojure

守給你的承諾、 提交于 2019-12-07 03:56:00
问题 I have the following routes definition: (require '[compojure.core :as ccore] '[ring.util.response :as response]) (def *main-routes* (ccore/defroutes avalanche-routes (ccore/GET "/" [] "Hello World 2") (ccore/GET "/images/:id" [id] (get-image-response id)))) In this example, requesting / works like a charm and returns the expected Hello World 2 . The get-images-response method is defined like this: (defn get-image-response [id] (let [record (db/get-image id false)] (-> (response/response (

StreamReader and binary data

走远了吗. 提交于 2019-12-07 03:32:23
问题 I have this text file what contains different fields. Some fields may contain binary data. I need to get all the data in the file but right now when using StreamReader then it wont read the binary data block and data what comes after that. What would be the best solution to solve this problem? Example: field1|field2|some binary data here|field3 Right now i read in the file like this: public static string _fileToBuffer(string Filename) { if (!File.Exists(Filename)) throw new

Full-text search on MongoDB GridFS?

家住魔仙堡 提交于 2019-12-07 01:26:22
问题 Say, if I want to store PDFs or ePub files using MongoDB's GridFS, is it possible to perform full-text searching on the data files? 回答1: You can't currently do real full text search within mongo: http://www.mongodb.org/display/DOCS/Full+Text+Search+in+Mongo Feel free to vote for it here: https://jira.mongodb.org/browse/SERVER-380 Mongo is more of a general purpose scalable data store, and as of yet it doesn't have any full text search support. Depending on your use case, you could use the

how to parse binary files in Clojure

血红的双手。 提交于 2019-12-06 22:03:56
问题 What is the cleanest way to parse binary data in clojure? I need to be able to read/write equally cleanly to a file or a socket. something like: (read-data source-of-data) => { :index 42 , :block-size 4 , data-size: 31415, :data (1 2 3 4 ...)} and the reverse for putting data back. It would be really great to somehow define the structure once and have the read and write functions use the same definition. 回答1: Gloss makes it easy to define binary formats at the byte level for both reading and

Accessing binary data from Javascript, Ajax, IE: can responseBody be read from Javascript (not VB)?

心不动则不痛 提交于 2019-12-06 17:30:39
问题 First of all, I am aware of this question: How do I load binary image data using Javascript and XMLHttpRequest? and specifically best answer therein, http://emilsblog.lerch.org/2009/07/javascript-hacks-using-xhr-to-load.html. So accessing binary data from Javascript using Firefox (and later versions of Chrome which actually seem to work too; don't know about Opera). So far so good. But I am still hoping to find a way to access binary data with a modern IE (ideally IE 6, but at least IE 7+),

How to upload binary data using POST

谁都会走 提交于 2019-12-06 15:48:36
I have something like this in my code: String boundary = "thisIsMyBoundaryString"; StringBuilder body = new StringBuilder(); ... byte[] data = bos.toByteArray(); body.append(new String(data)); body.append("\r\n--" + boundary + "--\r\n"); String entity = body.toString(); I'm building a POST request and need to insert some binary data (JPEG compressed bitmap). After appending byteArray, I want to append newLine and boundary string, but the StringBuilder gets corrupted - seems that the bytes from the added boundary become misaligned from that point on and they are no longer being interpreted as