base64 to file in java6 with data longer than 65000 - file

I've Base64 code that i need to open it as file , i used DatatypeConverter.parseBase64Binary which is working fine with data less than 65000 , but the issue that i receive codes which is longer than that how can i manage this in JAVA6 ???
Below is the Code i'm using , which is working fine with code less than 65000
CREATE OR REPLACE JAVA SOURCE NAMED "BlobHandler" AS
import java.lang.*;
import java.sql.*;
import oracle.sql.*;
import java.io.*;
import javax.xml.bind.DatatypeConverter;
public class BlobHandler
{
public static void ExportBlob(String CONTFILE, BLOB CONTBLOB) throws Exception
{
try
{
File file = new File("/u01/oracle/jam_export/contract1");
FileOutputStream fos = new FileOutputStream(file);
//Decoding
byte[] decoded = DatatypeConverter.parseBase64Binary("JVBERi0xLjcNCiW1");
System.out.println("PDF File Saved");
fos.write(decoded);
fos.flush();
fos.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
};
Note DatatypeConverter.parseBase64Binary("JVBERi0xLjcNCiW1"); is a part of the BASE64 code for the post character limitation

Related

What is the use of System.getProperty() while taking Screenshot in Selenium?

I'm running a program for adding screenshot in extent report automatically using selenium. Program is running perfectly,but I want to know the meaning of System.getProperty line in below program .
public class SST
{
public static String getScreenshot(WebDriver driver)
{
TakesScreenshot ts=(TakesScreenshot) driver;
File src=ts.getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir")+"/Screenshot/"+System.currentTimeMillis()+".png";
File destination=new File(path);
try
{
FileUtils.copyFile(src, destination);
} catch (IOException e)
{
System.out.println("Capture Failed "+e.getMessage());
}
return path;
}
}
It is getting the user home directory, for example, C:\Users\user10796675.

What are the steps to opening a .dat file in java?

I have another assignment which is obviously giving me trouble.
I need to write code that will open a .dat file from my hard drive in Netbeans IDE.
The file doesn't contain binary data just simple text characters.
When I run the code I've written it gives an error...because it cannot locate the file. Any Suggestions
package countedcones;
import java.io.*;
public class CountedCones {
public static void main(String[]args) throws IOException{
FileReader in = new FileReader("icecream.dat");
BufferedReader br = new BufferedReader(in);
String line = br.readLine();
while (line!=null) {
System.out.println(line);
line = br.readLine();
}
in.close();
}
}

What does 'moveFailed' really do?

I want to create a file input that behaves as follows:
Process the exchange
Attempt to copy the input file to a shared drive
If step (2) fails (e.g. share is down) then move to local file instead
Following the doc the 'moveFailed' parameter allows to "set a different target directory when moving files after processing (configured via move defined above) failed". So this sounds like the moveFailed would cover step (3).
The following test, however fails...what am I doing wrong ? I am using camel 2.10.0.fuse.
package sandbox.camel;
import java.io.File;
import org.apache.camel.Endpoint;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
public class MoveFailedTest extends org.apache.camel.test.junit4.CamelTestSupport {
private String failedDir = "move-failed";
#Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
#Override
public void configure() throws Exception {
from("file:tmp/prepare").to("file:tmp/input");
from("file:tmp/input?move=/doesnotexist&moveFailed=" + failedDir).to("file:tmp/output");
}
};
}
#Test
public void test_move() throws Exception {
// arrange
File moveFailedDir = new File("tmp/input/" + failedDir);
moveFailedDir.mkdirs();
File[] failedCount1 = moveFailedDir.listFiles();
failedCount1 = failedCount1 == null ? new File[0] : failedCount1;
String messagePayload = "Hello";
Endpoint input = getMandatoryEndpoint("file:tmp/prepare");
MockEndpoint output = getMockEndpoint("mock:file:tmp/output");
output.setMinimumExpectedMessageCount(1);
output.expectedBodiesReceived(messagePayload);
// act
template.asyncSendBody(input, messagePayload);
Thread.sleep(3000);
// assert: only 1 output
assertMockEndpointsSatisfied();
// assert: renamed failed, hence input file was moved to 'movefailed' directory
File[] failedCount2 = moveFailedDir.listFiles();
assertEquals("No file appeared in 'movefailed' directory", failedCount1.length + 1, failedCount2.length);
}
}
Your test is most likely wrong. The autocreate option is default true, which means directories is created if needed.

JNI byteArray passing help

I have been running into issues with my Android app closing (no errors or anything) when trying to execute the following code:
JNIEXPORT void Java_teamjeff_oggstreamtest_MainTest_audioFunc(JNIEnv* env, jobject obj) {
//<REMOVED VARIABLE INITIALIZATION>
jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID writeDataFunc = (*env)->GetMethodID(env, cls, "writeToAudioTrack", "([B)V");
if (!writeDataFunc) return;
jmethodID readDataFunc = (*env)->GetMethodID(env, cls, "readFromBuffer", "([B)I");
if (!readDataFunc) return;
rawDataRead = (*env)->NewByteArray(env, 4096);
bytes = (*env)->CallIntMethod(env, obj,readDataFunc, &rawDataRead);
char* carr = (*env)->GetByteArrayElements(env, rawDataRead, NULL);
memcpy(buffer, carr, bytes);
(*env)->DeleteLocalRef(env, rawDataRead);
//<REMOVED REST OF FUNCTION>
}
I've tracked the "trouble" code to the bytes = (*env)->CallIntMethod(env, obj,readDataFunc, &rawDataRead); line. If I return before this line, my app doesn't close, but if I return immediately after this line, my app closes randomly without even an error.
Here is the JAVA code:
package teamjeff.oggstreamtest;
import android.app.Activity;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.os.Bundle;
import android.os.Handler;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import com.Ostermiller.util.CircularByteBuffer;
public class MainTest extends Activity {
public static Handler mHandler = new Handler();
private final CircularByteBuffer cbb = new CircularByteBuffer(1024*512, true);
public AudioTrack mAudioTrack;
static {
System.loadLibrary("vorbis-decoder");
}
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
final Socket test = new Socket(InetAddress.getByName(<HOME SERVER URL>), <PORT>);
new Thread(
new Runnable(){
public void run(){
try {
while(!test.isClosed()) {
byte[] temp = new byte[4096];
int bytes = test.getInputStream().read(temp, 0, 4096);
cbb.getOutputStream().write(temp, 0, bytes);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
).start();
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
44100,
AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_16BIT,
1024*64,
AudioTrack.MODE_STREAM);
mAudioTrack.play();
new Thread(new Runnable() {
public void run() {
audioFunc();
}
}).start();
} catch (Exception e) {
e.printStackTrace();
}
}
public native void audioFunc();
#SuppressWarnings("unused")
private void writeToAudioTrack(final byte[] media) {
mHandler.post(new Runnable() {
public void run() {
mAudioTrack.write(media, 0, media.length);
}
});
}
#SuppressWarnings("unused")
private int readFromBuffer(byte[] buffer) {
try {
return cbb.getInputStream().read(buffer, 0, buffer.length);
} catch (IOException e) {
e.printStackTrace();
}
return -1;
}
}
I have searched for days here and on Google on how to accomplish what I want to do. My code above is the gluing together of various code snippets I've found around the internet with tweaks to fit my use-case.
What I'm trying to accomplish:
I will read in data from a socket in my Android App, pass this data to my C code for decoding (though the algorithm reads it in piece by piece during the algorithm, meaning I can't pass in the byteArray from Java to C and call my C function multiple times since the decoder sometimes uses data from previous read-in bytes). My C code does the decoding, and passes the PCM data back to my Android app to be played on an AudioTrack.
I am using a circular buffer to buffer in the data from the socket.
When I try to debug my Android App, I set break points at the entries to both the read and write functions and they never seem to be called.
Am I doing something wrong when I pass the byteArray from my C code to JAVA to be filled with data? Should I be doing this an alternative way?
A few notes that might help.
&rawDataRead is wrong. Lose the &. You just pass the ref that you get, not the address of it.
you don't need to delete that local ref. All local refs are deleted when a native function returns. I'm fairly confident that this is true in java, but the android situation may be different.
You don't have to keep retrieving the method ids. You can get them once and hang onto them.

how to create thumbnail system for MP4 files

I know I know, why am I using MP4 still?? It's because I have like 100 files already in this format and I need to upload to a website, I have the mp4 file embeded in the site already and the file played changes according to php.
but what I really need is a way to dynamically create a thumbnail or take a snapshot of the video file to display on the page. I've read a couple things online but they all require the file type to be in FLV, what would be the best way to accomplish this?
Thank you Guys!
have you looked at ffdshow? You can program against it, including capturing thumbnails.
package com.tape.controller;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.imageio.ImageIO;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.OpenCVFrameGrabber;
public class VideoThumbTaker {
protected String ffmpegApp;
public VideoThumbTaker(String ffmpegApp)
{
this.ffmpegApp = ffmpegApp;
}
public void getThumb(String videoFilename, String thumbFilename, int width, int height,int hour, int min, float sec)
throws IOException, InterruptedException
{
ProcessBuilder processBuilder = new ProcessBuilder(ffmpegApp, "-y", "-i", videoFilename, "-vframes", "1",
"-ss", hour + ":" + min + ":" + sec, "-f", "mjpeg", "-s", width + "*" + height, "-an", thumbFilename);
Process process = processBuilder.start();
InputStream stderr = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null);
process.waitFor();
}
public static void main(String[] args) throws Exception, IOException
{
FFmpegFrameGrabber g = new FFmpegFrameGrabber("C:\\JavaEE\\New Project\\tape\\src\\main\\webapp\\web-resources\\videos\\vid.mp4");
g.setFormat("mp4");
g.start();
for (int i = 0 ; i < 50 ; i++) {
ImageIO.write(g.grab().getBufferedImage(), "png", new File("C:\\JavaEE\\New Project\\tape\\src\\main\\webapp\\web-resources\\thumbnails\\video-frame-" + System.currentTimeMillis() + ".png"));
}
g.stop();
}
}
I have used this Java code using FFMpegFrameGrabber to create thumnails of a video. Try it out.
Maven Dependency :
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>0.8</version>
</dependency>

Resources