How to create bytes in Java to send payload to APNS - java

I need to build a APNS provider program for my app.
I was previously using PHP to do this trick and everything's been working fine thanks to the abstraction offered by dear PHP.
But now I have to handle this task in Java. I do not want to use 3-rd party library in my code-base since I really need total control and customization. While I am trying I quickly find It becoming way more bare-metal.
I barely know how to work with bytes in java. I searched on Google for quite a while only to find that the information about building APNS provider in Java is amazingly rare considering popularity of Java.
To be specific:
I got device token as String deviceToken. And payload in String(JSON format) payload.
How do I write them to outputStream to be in line with binary format required by Apple?
Thanks guys!

I dont know why you wanted to recreate the wheel, but you can check this source codes:
https://code.google.com/p/javapns/source/browse/trunk/src/javapns/communication/ConnectionToAppleServer.java
https://code.google.com/p/javapns/source/browse/trunk/src/javapns/notification/Payload.java (this is the actual payload)
In any case, instead of rebuilding everything you can download the project and extend some classes for specific things you want to do. But as far as I know, that lib is pretty much complete, I used it in 2 projects and it works pretty well.

Related

Is there any way I can try to read files with suffix like '.sas7bdat', '.dta', '.sav' and '.xpt' by using JAVA?

I am working on a module, which can import different kinds of files(currently those file types are SAS output format). Of course, this module is written by java, springboot. The main logic is that when user upload a file, the controller will pass the file inputstream to this module, and call the corresponding method by the file's suffix.
I have done some investigation and found that R-language and python could do this. Can anybody tell me whether there is another way, I mean, can do this job only by JAVA. Thanks.
The sas7bdat is a binary, proprietary format. Its layout has never been made public. Some people have figured it out (like the parso mentioned in the comment). If you really want to go down this path, use the python library as a guide. It will help with sas7bdat and sas7bcat. For the old SAS transport format, see my library on GitHub which is in C#. The new transport format appears to have some incorrect information in its description on the SAS website which I couldn't get around. I have put my code on GitHub in case you want to try.
All that said, let me offer a few words of wisdom: don't do it. Use the python library vs doing it in Java. Also, these libraries read the format vs having read/write. Keep that in mind (it sounds like it doesn't matter but FYI).

Is there a tool/API to extract Minecraft recipes?

A friend and I decided to code a discord bot in Java, using JDA. The idea is for the bot to give you a request Minecraft recipe (a picture of it). However, we don't want to have to download every single recipe (there are way too many of them). So I was wondering if there's something we can use that would give us the recipes with pictures and everything, like an API or a website that we can access from the Java code that would return something we can use. (No code attached since we haven't really done anything and it would serve no purpose).
I am not sure if an API exists that can do that for you. If the problem is spending the time to download every single recipe I might recommend creating a webscraper that could get that data from you. Getting the images from a site like https://www.minecraftcrafting.info/ would be fairly straight forward using python and beautifulsoup (https://pypi.org/project/beautifulsoup4/). Hope that helps and good luck!

1-D barcode scanner(using images from a capturing device) implementation in java

I am a student and as a project i have to implement a barcode(1-D) based attendance marking system.While surfing across the web i came to know that barcode readers are a bit costly toys to purchase,so now what I want to do is I want to capture images of barcodes through a capturing device(mostly a webcam) and then process them to get the content stored in it.
I found a few projects on the internet that do the same but they use .NET f/w and I am not so familiar with .NET technology. The only project that uses java is http://sourceforge.net/projects/javabarcoderead/ but somehow i am not able to run the jar file they are providing.
SO, I would like to know about the algorithms or methods that can be used for the same or even any project from where i can get some insight on how to move further with this...
Happy Coding...
You're right, it would be very difficult to use a library with no documentation and no source code.
I'd suggest using ZXing. It's a well-documented library with lots of examples.

JavaNNS - Parsing the created Neural Network

I'm currently working on a Neural Network for creating a "better" PNG Predictor (Prefilter).
I already created the network (with JavaNNS) which has a quite good learning rate on 8-Bit grayscale images.
Now my next step would be to include this created network in my prepared PNG Encoder/Decoder which is written in Java. But to do that I need to parse the created .net file from JavaNNS.
I don't want to invent the wheel again so is there any chance that another one of you has already written a simple parser for the .net files of the JavaNNS which would read all the layers with the neurons, the connections and the weights on the connections and store it in any usable Java data structure?
I know it isn't that hard to create a parser, but it would be awesome to save time and skip this "boring" task.. :)
Thanks!
JavaNNS's predecessor, SNNS (alternative link), had an export function which exported the trained network as C code (essentially a header and source file pair). These files could then be used in custom code.
In Java you could use JNI or JNA to call C code and I am sure there are threads here on SO how to accomplish this.
I do not know the current version of JavaNNS, but maybe they already provide an export function exporting the network as Java code instead of C? Or you could open your trained network in the old SNNS and export it?
I just wanna add that I've created my own .net (JavaNNS) File Parser in Java. It is possible to parse single hidden layer networks. If anyone needs the code who run into the same problem I had before I am happy to share my code.
You can contact me on my blog. Here is the post about the Neural Network Project I've done. Just let a comment there and I will provide you the JavaNNS Parser and the corresponding NeuralNetwork Class.
http://prineblog.wordpress.com/2011/06/21/neural-network-as-predictor-for-image-coding-png/
I just updated the Version of Nen to Beta - It is a lightweight 3-layer neural network implementation in Java for regression and classification. A little performance comparison against support vector machines (LibSVM) demonstrates its capabilities. It can be used via command line or Java.

Large file uploads with Java applet

I've been tasked with implementing large (2gb+) file uploads via a web browser. After evaluating various technologies, java applets seem to be the way forward (only one's which provide proper access to the local disk). I was wondering if anyone can recommend a 3rd party file upload app we can use as a base? requirements are
Decent UI, ideally we want something similar to facebooks photo uploader
Can handle large (2gb+) files
Resumable uploads
We beed the source to extend it to our needs (dont mind paying extra)
You're probably looking for JUpload.
Update: not sure if it has as nice of UI as you're hoping, but unless you want to build a custom solution like I have it's your best option.
Just a tip, maybe it is obvious, i don't know :P
It is nice to send the big file in chunks like 2mb, and on the server side you just append the bytes to the target file. The server knows what bytes it needs, and if a upload is aborted and continued later, the server can just send a message about from what bytes to start uploading the file again. Then we get resumability (is it a word? :P) and safety of large HTTP-uploads (since, in fact, we are sending many smuller uploads, and each upload is checked to be of the correct size on the server).
We wrote an implementation like this once with a Java-applet as the client and PHP on the server, I'll see if I can dig it out as a reference for you :p
Not really a solution : from experience you may bump into the following issues:
problems when uploading over HTTPs
problems uploading through proxies
Just wanted to make you aware of these two cases, for you to test when evaluating a solution.
Hope, you will get solutions for your prob over here.. http://jupload.sourceforge.net/

Categories

Resources