How to invoke applications on BlackBerry - java

I'm new on this world of BlackBerry and the thing is that i have a byte array of certain file that can be anything (picture, pdf, txt ...) and need to be shown. How can i execute applications related with the specific extention? In other words how can i invoke an application and give it the byte array to be displayed as the original file?
I also have the extention or file type.
I have tried to open the file using browsers but it always return timeout and that's not the idea.
Here is something like my question but it has not a final response. I'm developing for BlackBerry Curve.

I have never used it, but I think the appropriate API for this is the Content Handler API, most commonly referred to as CHAPI I think. Look for documentation of javax.microedition.content. Here is a link that will take you to the ContentHandler class.
I suggest that you look for the chapidemo sample for more information. It should have come with your tooling, if not, here it is on github: chapidemo sample.

Related

Need a head start in reading AFP files and extracting the content and metadata

I was assigned to work on this specific project, where we will be getting AFP(advanced function presentation) files and we need to get the documents, i.e.the content and the corresponding meta data. I have been looking into AFP(advanced function presentation) file format and haven't actually got any useful resource about how I should proceed with the task.
I have almost got no information up until now and don't know where to proceed. I looked into some open source projects and found this: https://github.com/yan74/afplib
I tried running it.. But it does not work on the sample AFP file which I have.
Really need some insight upon what resources should I go through to be able this project.
I need to write the code in Java and have gone through some licensed softwares which do the same,like PROARCHIVER and PAPYRUS.
Thanks in advance
AFP is an easy format, it's composed of structured fields, your first step is decoding them, download this: "Mixed Object Document Content Architecture Reference" read first 50 pages and write code to split afp into structured fields, in order to create an easy dump of your file.
After that if you want to extract images AFP world calls them IOCA, so you need: Image Object Content Architecture reference
If you want to extract text (called PTX) you need: Presentation Text Object Content Architecture Reference
good job

How to give format and print data to a ticket printer in Java

I'm starting to do anything like this, so I need a little bit of help to start with.
I want to print some data and give it a format to print it as an establishment ticket, so what would be the best way?
Using the java api and create the service by myself?
http://docs.oracle.com/javase/tutorial/2d/printing/index.html
Or does it exist any free library to this purpose?
Maybe better creating a PDF with the data before printing?
I've been messing around with PDFbox API but I don't like it very much.
I don't know what printer will be used so, do ticket printers use a standard size or exists differents ticket sizes?
I also need to show a preview before printing it (I'm using Swing).
There's no need to store the formatted data.
Thanks in advance.
If You decide to generate pdf file and then print it, I propose to use Apache FOP. I always use this library to generate PDF. This library is not easy but offers many options.
Second option - You could generate HTML page and then print it.
From a real live example: we're running a project that prints despatch labels to send a package with a parcel service. The label contains barcodes and other textual information as well as a logo.
Usually a ticket printer understands a special printer control language, i.e. if it's a Zebra printer it understands EPL or ZPL-code. To produce a ticket we simply send the whole control code over a simple socket connection to the printer. The control code itself is created through a template engine (Velocity in our case).
Of course there are different printers for different requirements - it may depend on what actually should be printed. So depending on the printer you may need to create a different set of template to produce your label:
https://en.wikipedia.org/wiki/Printer_control_language
By the way:
Usually the printer comes with software to let you design the layout of the paper label (which makes life really easy). We used this software to create the initial layout. The control code itself contains all commands used to configure the printer (label size, etc - no doubt there are plenty of different formats and sizes, as said: it really depends on the use case).

How to get specific file details under windows?

Which is the easiest way I could get the file details / properties under windows?
I am not talking about common properties (such as file size, creation date), but the ones written by variuos software. In my particular case I need to get the detail called "Date taken" for a jpg image file.
I could use PHP, Java or VB.NET, whatever is easier.
My final goal: I have a bunch of images I took with different versions of Android on my phone. They are all named with different naming convention, most of them just something like IMG_[consecutive_numbers].jpg. So I want to rename them all, but for that I need their original creation date, and since I have moved them from my pc to the phone and back so many times, I cannot trust the "creation date" property. I found that all of them have a property which was set by the camera called "Date taken", which is still intact and valid.
Thanks in advance!
P.S.:
This is what I need:
Is this what you are looking for?
http://php.net/manual/en/function.exif-read-data.php
I believe the photo you have posted actually shows something pulled from the exif data.
Knowing this you can use any language that has the ability to extract the exif data.
For java their is no native way so you would use a library such as http://www.drewnoakes.com/code/exif/
I am a ava developer so I have provided a Java option; however, this can be done in any language.
Dim finfo As New System.IO.FileInfo(fdialog.FileName)
now you can play around with all the fileinfo attribures.
regards ...

How do I send a query to a website and parse the results?

I want to do some development in Java. I'd like to be able to access a website, say for example
www.chipotle.com
On the top right, they have a place where you can enter in your zip code and it will give you all of the nearest locations. The program will just have an empty box for user input for their zip code, and it will query the actual chipotle server to retrieve the nearest locations. How do I do that, and also how is the data I receive stored?
This will probably be a followup question as to what methods I should use to parse the data.
Thanks!
First you need to know the parameters needed to execute the query and the URL which these parameters should be submitted to (the action attribute of the form). With that, your application will have to do an HTTP request to the URL, with your own parameters (possibly only the zip code). Finally parse the answer.
This can be done with standard Java API classes, but it won't be very robust. A better solution would be HttpClient. Here are some examples.
This will probably be a followup question as to what methods I should use to parse the data.
It very much depends on what the website actually returns.
If it returns static HTML, use an regular (strict) or permissive HTML parser should be used.
If it returns dynamic HTML (i.e. HTML with embedded Javascript) you may need to use something that evaluates the Javascript as part of the content extraction process.
There may also be a web API designed for programs (like yours) to use. Such an API would typically return the results as XML or JSON so that you don't have to scrape the results out of an HTML document.
Before you go any further you should check the Terms of Service for the site. Do they say anything about what you are proposing to do?
A lot of sites DO NOT WANT people to scrape their content or provide wrappers for their services. For instance, if they get income from ads shown on their site, what you are proposing to do could result in a diversion of visitors to their site and a resulting loss of potential or actual income.
If you don't respect a website's ToS, you could be on the receiving end of lawyers letters ... or worse. In addition, they could already be using technical means to make life difficult for people to scrape their service.

Java: Where can I find advanced file manipulation source/libraries?

I'm writing arbitrary byte arrays (mock virus signatures of 32 bytes) into arbitrary files, and I need code to overwrite a specific file given an offset into the file. My specific question is: is there source code/libraries that I can use to perform this particular task?
I've had this problem with Python file manipulation as well. I'm looking for a set of functions that can kill a line, cut/copy/paste, etc. My assumptions are that these are extremely common tasks, and I couldn't find it in the Java API nor my google searches.
Sorry for not RTFM well; I haven't come across any information, and I've been looking for a while now.
Maybe you are looking for something like the RandomAccessFile class in the standard Java JDK. It supports reads and writes at some offset, as well as byte arrays.
Java's RandomAccessFile is exactly what you want.
It includes methods like seek(long) that allow you to move wherever you need in the file. It also allows for reading and writing at the same time.
As far as I know, Java has primarily lower level functions for manipulating files directly. Here is the best I've come up with
The actions you describe are standard in the Swing world, and for text comes down to manipulating a Document object. These act on data in memory. The class java.nio.channels.FileChannel has similar methods that act directly on a file. Neither fine the end of lines automatically, but other classes in java.io and java.nio do.
Apache Commons has a sandbox library called Flatfile which looks like it does what you want. The problem is that no code has been released yet. You may, however, want to talk to people working on it to get some more ideas. I didn't do a general check on libraries.
Have you looked into File/FileReader/FileWriter/BufferedReader? You can get the contents of the files and manipulate it as you like, you can search the data in the files, you can overwrite files, create new, append to an existing....
I am not sure this is exactly what you are asking for but I use these APIs all the time for logging, RTF editors, text file creation for email, and many other things.
As far as cut/copy/past goes, I have not come across the ability to do that directly, however, you can output the contents of the file and "copy" what part of it you want and "paste" it into a new file, or append it to an existing.
While writing a byte array to a file is a common task, writing to a give file 32-bytes byte array just once is just not something you are going to find in java.io :)
To get started, would the below method and comments look reasonable to you? I bet someone here, maybe even myself, could whip it out quick like.
public static void writeFauxVirusSignature(File file, byte[] bytes, long offset) {
//open file
//move to offset
//write bytes
//close file
}
Questions:
How big could the potential target files be?
Do you need performance?
I ask because clean, easy to read code would use Apache Commons lib's, but large file writes in a performance sensitive environment will necessitate using java.nio libraries

Categories