I'm trying to implement the tTorrent client into my program, I've looked at this link for an example (https://github.com/mpetazzoni/ttorrent/issues/16) and placed that code into the Download class of my program. Here is the code:
import statements:
import main.java.com.turn.ttorrent.client.Client;
import main.java.com.turn.ttorrent.client.SharedTorrent;
import main.java.com.turn.ttorrent.common.Torrent;
import main.java.com.turn.ttorrent.tracker.TrackedTorrent;
import main.java.com.turn.ttorrent.tracker.Tracker;
// Create tracker instance
Tracker tracker = new Tracker(InetAddress.getLocalHost());
// Load torrent file
File torrentFile = new File("/path/to/torrentFile.torrent");
// Create torrent instance
TrackedTorrent torrent = new TrackedTorrent(Torrent.load(torrentFile, null));
// Announce torrent
tracker.announce(torrent);
// Start the tracker
tracker.start();
torrentFile = new File(path + ".torrent");
File downloadDir = new File("/path/to/torrents_download_dir");//unsure
Client client = new Client(InetAddress.getLocalHost(), SharedTorrent.fromFile(torrentFile, downloadDir));
// Add client.share(); if you wish to share the torrent infinitely
client.run();
I'm getting this error message when I hover over load:
The method load(File, boolean) in the type Torrent is not applicable for the arguments (File, null)
I'm also unsure what I should place in File downloadDir. I'm still a beginner and if someone could point me in the right direction to putting this into my program that would be great. I'm still a beginner.
Torrent.load(torrentFile, null) wants a File object.
e.g
Torrent.load(new File(/foo/path.torrent), null)
Try to write your objects and method in a main Method
public static void main(String[] args) {
// Object 1;
// Object 2;
}
Related
I'm using R programing to analysis FFT . now I want to make Java web application/ java servlet and calling R to use Rcaller/Rcode for it . I have some reference about Calling Rcode in java application. http://code.google.com/p/rcaller/wiki/Examples
I have CSV File
for example A.csv
time Amplitude
1 0.00000 -0.021
2 0.00001 -0.024
3 0.00003 -0.013
4 0.00004 -0.023
5 0.00005 0.019
6 0.00007 -0.002
7 0.00008 -0.013
then I want to upload this file and use R Code for analysis FFT and Plot it.
Help is much appreciated! Thanks in advance, Maria
You start creating an instance of RCaller and set the current location of install Rscript.exe file. You can start with
RCaller caller = new RCaller();
Globals.detect_current_rscript();
caller.setRscriptExecutable(Globals.Rscript_current);
RCode code = new RCode();
or you can give the exact location
RCaller caller = new RCaller();
caller.setRscriptExecutable("c:\\path\\to\\Rscript.exe");
RCode code = new RCode();
Suppose your data is saved in a file mydata.csv.
code.addRCode("dat <- read.cvs(\"mydata.csv\", header=T, sep=\",\"");
then we are plotting the Amplitude
File file = code.startPlot();
code.addRCode("plot.ts(dat$Amplitude)");
code.endPlot();
and sending our code to R:
caller.setRCode(code);
caller.runOnly();
And now, the file variable holds the image data. It can be shown on screen using the code
code.showPlot(file);
For further reading, follow the blog entries on stdioe blog
When I execute this code is running but didn't show anything !!!!!!!
package test2;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.swing.ImageIcon;
import rcaller.RCaller;
import rcaller.RCode;
import rcaller.exception.RCallerExecutionException;
import rcaller.exception.RCallerParseException;
public class Test2 {
public static void main(String[] args) {
Test2 test2=new Test2();
}
private int span;
#SuppressWarnings("empty-statement")
public void test2()throws IOException{
try {
RCaller caller = new RCaller();
caller.setRscriptExecutable("C:\\Program Files\\R\\R-3.0.3\\bin\\Rscript.exe");
RCode code = new RCode();
code.addRCode("dat<-read.csv(\"NetBeansProjects\"test2\"A.csv\",header=T,sep=\",\"");
File file=code.startPlot();
code.addRCode("plot.ts(dat$Amplitude)");
code.endPlot();
caller.setRCode(code);
caller.runOnly();
ImageIcon i=code.getPlot(file);
code.showPlot(file);
} catch (RCallerExecutionException | RCallerParseException e) {
System.out.println(e.toString());
}
}
}
I have to connect RFID reader with my java project. I installed all necesary driver for this device and imported all necesary Libraries. I used Eclipse program to writing my java project.
Am beginner with RFID readers. The below code doesn't work. Please help me.
package com.caen.RFIDLibrary;
import com.caen.RFIDLibrary.CAENRFIDException;
import com.caen.RFIDLibrary.CAENRFIDLogicalSource;
import com.caen.RFIDLibrary.CAENRFIDPort;
import com.caen.RFIDLibrary.CAENRFIDReader;
import com.caen.RFIDLibrary.CAENRFIDReaderInfo;
import com.caen.RFIDLibrary.CAENRFIDTag;
public class reader_com {
public static void main (String[] args) throws CAENRFIDException{
CAENRFIDReader MyReader = new CAENRFIDReader(); //Create myObject
CAENRFIDReaderInfo Info = MyReader.GetReaderInfo(); // Create Object for reader info
String Model = Info.GetModel(); //Get info about model
String SerialNumber=Info.GetSerialNumber(); // Get info about serialNumber
String FWRelease = MyReader.GetFirmwareRelease(); // Get info about FW
MyReader.Connect(CAENRFIDPort.CAENRFID_USB, "COM13"); // Open a connection
CAENRFIDLogicalSource MySource = MyReader.GetSource("Source_0, Source_1"); // Choose Source 0-->RFID tags 1-->Barcode
MySource.SetQ_EPC_C1G2(3); // set Q Value
CAENRFIDTag[] MyTags = MySource.InventoryTag();
if (MyTags.length > 0){
System.out.println(Model);
System.out.println(SerialNumber);
System.out.println(FWRelease);
}
MyReader.Disconnect();
}
}
And i get back this error:
Exception in thread "main" java.lang.NullPointerException
at com.caen.RFIDLibrary.CAENRFIDReader$IOBuffer.access$1800(CAENRFIDReader.java:228)
at com.caen.RFIDLibrary.CAENRFIDReader$CAENRFIDOutPacket.AddHeader(CAENRFIDReader.java:2701)
at com.caen.RFIDLibrary.CAENRFIDReader.GetReaderInfo(CAENRFIDReader.java:3183)
at com.caen.RFIDLibrary.reader_com.main(reader_com.java:20)
In order to get any information about the reader (or call any other method of the CAENRFIDReader object), you first need to connect to it. So the flow of your program would be like this:
CAENRFIDReader myReader = new CAENRFIDReader();
myReader.Connect(CAENRFIDPort.CAENRFID_RS232, "COM13");
CAENRFIDReaderInfo info = MyReader.GetReaderInfo();
String model = info.GetModel();
String serialNumber = info.GetSerialNumber();
String fwRelease = myReader.GetFirmwareRelease();
CAENRFIDLogicalSource mySource = myReader.GetSource(...);
Also note, that if your reader is available on COM13, you would likely need to use CAENRFIDPort.CAENRFID_RS232 and not CAENRFIDPort.CAENRFID_USB.
I am using xugglu in java in order to switch the bitrate of the input MP3 file, storing it in a output file. I took one example I found on the net the loads the file to a reader and adds a writer as a listener. Does anyone know how can I then modify the bitrate?
Here's the code I've been using:
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaViewer;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import org.slf4j.LoggerFactory;
public class TranscodingExample {
private static final String inputFilename = "/home/user/Desktop/file_changed.mp3";
private static final String outputFilename = "/home/user/Desktop/file_changed.flv";
public static void main(String[] args) {
// create a media reader
IMediaReader mediaReader =
ToolFactory.makeReader(inputFilename);
// create a media writer
IMediaWriter mediaWriter =
ToolFactory.makeWriter(outputFilename, mediaReader);
// add a writer to the reader, to create the output file
mediaReader.addListener(mediaWriter);
// create a media viewer with stats enabled
IMediaViewer mediaViewer = ToolFactory.makeViewer(true);
// add a viewer to the reader, to see the decoded media
mediaReader.addListener(mediaViewer);
// read and decode packets from the source file and
// and dispatch decoded audio and video to the writer
while (mediaReader.readPacket() == null) ;
}
}
EDIT-1:
I couldn't really get around this one, so I just used a linux command doing that inside the Java app. You can find a reference to the code here. The command I used was:
ffmpeg -i in.mp3 -b 112k out.mp3
It converts the mp3 to a new one of bitrate equal to 112k.
Take a look at IAudioResampler:
Used to resample IAudioSamples to different sample rates or number of channels.
Does this code require the Digital Persona One Touch RTE (Runtime environment) to work?:
DPFPVerification verifier = DPFPGlobal.getVerificationFactory().createVerification();
If so, is there another way to verify Digital Persona SampleFeatures (serialized) against a Digital Persona Template (serialized) using only the dpfp JARs?
Reason: We plan to have our DPFP verifier on a Web Service provided by TIBCO.
Any help is greatly appreciated!
I get a Java JNI exception with this sample test main code:
import com.digitalpersona.onetouch.DPFPFeatureSet;
import com.digitalpersona.onetouch.DPFPFeatureSetFactory;
import com.digitalpersona.onetouch.DPFPGlobal;
import com.digitalpersona.onetouch.DPFPTemplate;
import com.digitalpersona.onetouch.DPFPTemplateFactory;
import com.digitalpersona.onetouch.verification.DPFPVerification;
import com.digitalpersona.onetouch.verification.DPFPVerificationResult;
public class Main {
/**
* fingerScanTemplate is from WC DB
* sample is from the WS input parameters
*/
public boolean performVerification(byte[] fingerScanTemplate, byte[] sampleFeatures) {
DPFPTemplateFactory templateFactory = DPFPGlobal.getTemplateFactory();
DPFPFeatureSetFactory featureSetFactory = DPFPGlobal.getFeatureSetFactory();
DPFPVerification verifier = DPFPGlobal.getVerificationFactory().createVerification();
// Deserialize template & sampleFeature
DPFPTemplate deserializedTemplate = templateFactory.createTemplate(fingerScanTemplate);
DPFPFeatureSet features = featureSetFactory.createFeatureSet(sampleFeatures);
//Compare the feature set with the template, based on which finger was captured
DPFPVerificationResult result = null;
result = verifier.verify(features, deserializedTemplate);
return result != null && result.isVerified();
}
/**
* #param args
*/
public static void main(String[] args) {
new Main().performVerification(null, null);
}
}
No you should not need some sort of RTE. I do know that I had to have the One Touch SDK installed because it runs a windows service called Biometric scanning or something similar. The main problem I see with your code is that:
DPFPVerificationResult result = null;
result = verifier.verify(features, deserializedTemplate);
Needs to be:
DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
verifier.verify(features, template, ref result );
At least that is what got my code to start verifying correctly. I also had to fix a programmer's mistake in creating the FeatureSet which needs to be done like this:
DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);
I have a feeling you are using an older SDK than I am but maybe this will help out some.
I said in this question that I had some problem loading ptx modules in JCuda and after #talonmies's idea, I implemented a JCuda version of his solution to load multiple ptx files and load them as a single module. Here is the related part of the code:
import static jcuda.driver.JCudaDriver.cuLinkAddFile;
import static jcuda.driver.JCudaDriver.cuLinkComplete;
import static jcuda.driver.JCudaDriver.cuLinkCreate;
import static jcuda.driver.JCudaDriver.cuLinkDestroy;
import static jcuda.driver.JCudaDriver.cuModuleGetFunction;
import static jcuda.driver.JCudaDriver.cuModuleLoadData;
import jcuda.driver.CUjitInputType;
import jcuda.driver.JITOptions;
import jcuda.driver.CUlinkState;
import jcuda.driver.CUfunction;
public class JCudaTestJIT{
private CUmodule module;
private CUfunction functionKernel;
public void prepareModule(){
String ptxFileName4 = "file4.ptx";
String ptxFileName3 = "file3.ptx";
String ptxFileName2 = "file2.ptx";
String ptxFileName1 = "file1.ptx";
CUlinkState linkState = new CUlinkState();
JITOptions jitOptions = new JITOptions();
cuLinkCreate(jitOptions, linkState);
cuLinkAddFile(linkState, CUjitInputType.CU_JIT_INPUT_PTX, ptxFileName4, jitOptions);
cuLinkAddFile(linkState, CUjitInputType.CU_JIT_INPUT_PTX, ptxFileName3, jitOptions);
cuLinkAddFile(linkState, CUjitInputType.CU_JIT_INPUT_PTX, ptxFileName2, jitOptions);
cuLinkAddFile(linkState, CUjitInputType.CU_JIT_INPUT_PTX, ptxFileName1, jitOptions);
long sizeOut = 32768;
byte[] image = new byte[32768];
Pointer cubinOut = Pointer.to(image);
cuLinkComplete(linkState, cubinOut, (new long[]{sizeOut}));
module = new CUmodule();
// Load the module from the image buffer
cuModuleLoadData(module, cubinOut.getByteBuffer(0, 32768).array());
cuLinkDestroy(linkState);
functionKernel = new CUfunction();
cuModuleGetFunction(functionKernel, module, "kernel");
}
// Other methods
}
But I got the error of CUDA_ERROR_INVALID_IMAGE at calling cuModuleLoadData method. While debugging it, I saw that after calling cuLinkComplete method and pass the image array as the output, the array is still unchanged and clear. Am I passing the output parameter correctly? Is this how one can pass a variable by reference in JCuda?
I had never written a single line of Java code until 30 minutes ago, let alone used JCUDA before, but an almost literal line-by-line translation of the native C++ code I gave you here seems to work perfectly:
import static jcuda.driver.JCudaDriver.*;
import java.io.*;
import jcuda.*;
import jcuda.driver.*;
public class JCudaRuntimeTest
{
public static void main(String args[])
{
JCudaDriver.setExceptionsEnabled(true);
cuInit(0);
CUdevice device = new CUdevice();
cuDeviceGet(device, 0);
CUcontext context = new CUcontext();
cuCtxCreate(context, 0, device);
CUlinkState linkState = new CUlinkState();
JITOptions jitOptions = new JITOptions();
cuLinkCreate(jitOptions, linkState);
String ptxFileName2 = "test_function.ptx";
String ptxFileName1 = "test_kernel.ptx";
cuLinkAddFile(linkState, CUjitInputType.CU_JIT_INPUT_PTX, ptxFileName2, jitOptions);
cuLinkAddFile(linkState, CUjitInputType.CU_JIT_INPUT_PTX, ptxFileName1, jitOptions);
long sz[] = new long[1];
Pointer image = new Pointer();
cuLinkComplete(linkState, image, sz);
System.out.println("Pointer: " + image);
System.out.println("CUBIN size: " + sz[0]);
CUmodule module = new CUmodule();
cuModuleLoadDataEx(module, image, 0, new int[0], Pointer.to(new int[0]));
cuLinkDestroy(linkState);
CUfunction functionKernel = new CUfunction();
String kernelname = "_Z6kernelPfS_S_S_";
cuModuleGetFunction(functionKernel, module, kernelname);
System.out.println("Function: " + functionKernel);
}
}
which works like this:
> nvcc -ptx -arch=sm_21 test_function.cu
test_function.cu
> nvcc -ptx -arch=sm_21 test_kernel.cu
test_kernel.cu
> javac -cp ".;jcuda-0.7.0a.jar" JCudaRuntimeTest.java
> java -cp ".;jcuda-0.7.0a.jar" JCudaRuntimeTest
Pointer: Pointer[nativePointer=0xa5a13a8,byteOffset=0]
CUBIN size: 5924
Function: CUfunction[nativePointer=0xa588160]
The key here seems to be to use cuModuleLoadDataEx, noting that the return values from cuLinkComplete are a system pointer to the linked CUBIN and the size of the image returned as a long[]. As per the C++ code, the pointer is just passed directly to the module data load.
As a final comment, it would have been much simpler and easier if you had posted a proper repro case that could be been directly hacked on, rather than making me learn the rudiments of JCUDA and Java before I could create a useful repro case and get it to work. The documentation for JCUDA is basic, but complete, and against the working C++ example already provided, it only took a couple of minutes of reading to see how to do this.