Given an arbitrary .proto file, is it possible to parse it such that I can get all the messages defined using Java?
I know that I can create the source code using protoc and use reflection to get all the info I need but I want to avoid having to compile it.
I ended up using the --descriptor_set_out then used DescriptorProtos.FileDescriptorSet to create a FileDescriptor and this allowed me to use reflection to parse the file.
Related
I am using spring-data-mongodb version 2.1.5 and mongo-java-driver version 3.10.1. I need to parse a file to extract keywords. In order to do that I loaded file from db using com.mongodb.client.gridfs.model.GridFSFile, but I can't find any functions to convert this to java.io.File. Also I have a doubt in mongo-java-driver, what is the actual difference between com.mongodb.client.gridfs.model.GridFSFile and com.mongodb.gridfs.GridFSFile?
I actually managed to get File using GridFsResource. Used GridFsResource.getInputStream() and convert it to File using FileUtils.
This is the Jython script I have used to extract the ConfigProperties_server1.props file:
AdminTask.extractConfigProperties('[-propertiesFileName ConfigProperties_server1.props -configData Server=server1]')
Welcome to SO. The AdminTask.extractConfigProperties command has no option to control the format of the file. The option PortablePropertiesFile might sound promising, but instead it controls whether internal XMI ids are included in the props file. You're going to have to parse the properties file and convert it yourself, the syntax of the file is documented in this IBM KnowledgeCenter topic. Given the complexity of this task, you may want to edit your question and add some detail on what you're trying to accomplish by converting to xml or json format file, so perhaps the community might better help you.
Hi I need to view code of an .exe file which has to be loaded dynamically. So, is there any method of obtaining source code of an exe file in Java or do I need another language to do that?
Standard Java will presumably not be able to do this because what you want to do is platform specific.
I don't know any library that is able to do this.
What you could do is take the exe, extract its code segments and compare their content to a list of opcodes. You could then for example simply iterrate over the bytes and create a list how often hex 0x90 is found, which is an indication for a nop.
Perhaps it is a better solution to simply disassemble the file (into "sourcecode") and count the occurences based on their text representation.
I need to create a java API that takes in a CSV file and returns a JSON with some parsed data from the CSV. I've currently built a Java program in Eclipse with a bunch of static class methods that if passed in the file name of the CSV as a command-line argument to the main function, will do the parsing and create the JSON.
How do I go about modifying this code so that it will function as an API? In specific, the API should be able to accept a .csv file in the following way.
POST http://<YOUR HOST HERE>/scrub/:csv_file
Then, how do I go about returning the JSON? Thank you in advance for the help -- first time writing an API as opposed to a standard Java program.
Someone know one method to get the mime type from byte array? Attention, i want to do that without external library, only native java.
There is a way to do that using Java 7, but it is kind of clumsy (um tanto "desajeitado"):
write the bytes to a (temporary) file,
use Files.probeContentType(Path) to check the contents of that file
if the bytes came from a file you could use probeContentType directly on it.
EDIT:
not very useful, at least on Windows: probeContentType seams to primarily use the file extension to determine the file type [:-|