This error shows in Matlab under Linux whenever I try to paste a large array to matlab:
java.io.IOException: Owner failed to convert data
There is a bug report on Oracle's website and there's a workaround to it:
Fix: fix code in XSelection.java where, for incremental dataGetter.dispose() is called before validateDataGetter(dataGetter); in the method getData(long format, long time):
dataGetter.dispose();
ByteArrayOutputStream dataStream = new ByteArrayOutputStream(len);
while (true) {
WindowPropertyGetter incrDataGetter =
new WindowPropertyGetter(XWindow.getXAWTRootWindow().getWindow(),
selectionPropertyAtom,
0, MAX_LENGTH, false,
XConstants.AnyPropertyType);
try {
XToolkit.awtLock();
XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(),
incrementalTransferHandler);
propertyGetter = incrDataGetter;
try {
XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
XWindow.getXAWTRootWindow().getWindow(),
selectionPropertyAtom.getAtom());
// If the owner doesn't respond within the
// SELECTION_TIMEOUT, we terminate incremental
// transfer.
waitForSelectionNotify(incrDataGetter);
} catch (InterruptedException ie) {
break;
} finally {
propertyGetter = null;
XToolkit.removeEventDispatcher(XWindow.getXAWTRootWindow().getWindow(),
incrementalTransferHandler);
XToolkit.awtUnlock();
}
validateDataGetter(dataGetter);
However, I don't know what file to modify any java related class to matlab. Where should I look?
Related
I'm using a Jave program to get NSE share price data from NSE's website like this for example:
url = new URL("https://archives.nseindia.com/archives/equities/bhavcopy/pr/PR071122.zip");
f = new File("NSEData.zip");
try {
FileUtils.copyURLToFile(url, f);
} catch (Exception e) {
}
The above code works for dates where market data exists, like 07/11/22 . However, where data does not exist, like on 08/11/22, the url is broken and the copyURLToFile line gets stuck indefinitely during runtime (replacing 071122 with 081122 in the url/code above will cause it to get stuck). Is there an easy way to get the program to recognize that the url for a certain date is broken (eg. https://archives.nseindia.com/archives/equities/bhavcopy/pr/PR081122.zip) and therefore ignore and continue past the try block without getting stuck?
My current workaround is to check whether a certain date is a market holiday using a DayOfWeek check as well as a HashSet containing a list of public holidays, but this is not perfect.
So, basically your URL is returning 500 error upon requesting for invalid date. You can simply use the another method available in FileUtils
https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/FileUtils.html#copyURLToFile(java.net.URL,%20java.io.File,%20int,%20int)
Example code : (Adjust timeouts as per your requirement)
var url = new URL("https://archives.nseindia.com/archives/equities/bhavcopy/pr/PR081122.zip");
var f = new File("NSEData.zip");
try {
FileUtils.copyURLToFile(url, f, 5000, 5000);
} catch (Exception e) {
}
I am currently trying to incorporate a temporary stream in my card panel layed out like this.
Layout
Where it says scan your QRCode im trying to get a stream from the picam. Here is the issue.
I dont know how i can buffer that into the Java application
I got the command i want --> "raspistill -w 200 -h 200 -q 100 -t 5", but i just dont know how this would work. This is the first time im dealing with any video stream.
As for the second part. I need that "preview" to take a picture whenever it is able to grab the QRCode. I checked both apis for the raspberry pi camera but im still lost as in for direction. I also need this buffered so i can instantly parse it into my decodeQRCode method. What component do i need to accomplish this?
I decided to go with sarxos webcam api.
class VideoFeed extends Thread {
public void run() {
webcam.open();
boolean bool = true;
while (bool) {
try {
BufferedImage image = webcam.getImage();
var = BackEnd.refund(image,type[0]);
lblCamera.setIcon(new ImageIcon(image));
if (var[0] != null) {
bool = false;
webcam.close();
btnScan.doClick();
} else {
Thread.sleep(10);
}
} catch (InterruptedException ex) {
System.out.println("Error: " + ex);
}
}
}
}
started it by doing
new VideoFeed().start();
With this i opted for a more general driver.
I have to convert tif files to jpeg (although I've realized that it also fails for converting tif to any extension). My code works properly on my local windows machine but it doesn't work on my dev enviroment (which is a CentOs machine). This is my code (very simple as you could see):
public static boolean convertTIFFToJPEG(final File in, final File out) {
try {
final PlanarImage image = JAI.create("ImageRead", in);
final ParameterBlockJAI storeOperation = new ParameterBlockJAI(
"FileStore");
storeOperation.addSource(image);
storeOperation.setParameter("filename", out.getPath());
storeOperation.setParameter("format", "jpeg");
JAI.create("FileStore", storeOperation);
} catch (final IllegalArgumentException e) {
return false;
}
return true;
}
This code works fine in windows, however when I try to execute it on linux I get this error:
Caused by: java.lang.RuntimeException: - Unable to render RenderedOp for this operation.
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:827)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:888)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:799)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:888)
at javax.media.jai.JAI.createNS(JAI.java:1099)
at javax.media.jai.JAI.create(JAI.java:973)
at javax.media.jai.JAI.create(JAI.java:1395)
at example.TIFFUtils.convertTIFFToJPEG(TIFFUtils.java:97)
If I debug the application, to try to find out something more about the exception, I only get that the cause of it is 'Unable to render RenderedOp for this operation'.
To fix it, I've tried different versions of the Oracle JDK/JRE. Currently I'm using sdk1.6_20, but I also tried the last one and other previous distribution.
On the other hand, I've tried a lot of possibles ways to make the same process (TIFF->JPEG) by using JAI and ImageIO. This one is the code, that I used for ImageIO:
public static boolean convertTIFFToJPEG2(final File in, final File out) {
try {
ImageOutputStream ios = null;
ImageWriter writer = null;
// find an appropriate writer
Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName(JPEG_FORMAT);
if (it.hasNext()) {
writer = (ImageWriter)it.next();
} else {
return false;
}
ios = ImageIO.createImageOutputStream(out);
writer.setOutput(ios);
JPEGImageWriteParam writeParam = new JPEGImageWriteParam(Locale.ENGLISH);
BufferedImage image = ImageIO.read(in);
IIOImage iioImage = new IIOImage(image , null, null);
// write it!
writer.write(null, iioImage, writeParam);
} catch (final IllegalArgumentException e) {
return false;
} catch (IOException e) {
return false;
}
return true;
}
And I got the same result: it only works in windows but provokes that exception in linux. In this case the next instructions return null, so the variable 'image' doesn't contain anything.
BufferedImage image = ImageIO.read(tiffFile);
Any new idea?
I don't think all implementations of JRE (such as OpenJDK) included a Jpeg Encoder that could be used by default in JAI. I don't know if that's your problem though. Regardless, you might have better success by using the JAI Image IO Tools extension:
http://java.net/projects/imageio
http://www.oracle.com/technetwork/java/current-142188.html
This provides integration allowing JAI to use ImageIO libraries for image decoding/encoding which is generally much improved over the original JAI handling.
To further debug your problem, you might try temporary outputting to image format other than JPEG to see if your problem is specific to JPEG encoding.
Note: Please do not judge this question. To those who think that I am doing this to "cheat"; you are mistaken, as I am no longer in school anyway. In addition, if I was, myself actually trying to cheat, I would simply use services that have already been created for this, instead of recreating the program. I took on this project because I thought it might be fun, nothing else. Before you down-vote, please consider the value of the question it's self, and not the speculative uses of it, as the purpose of SO is not to judge, but simply give the public information.
I am developing a program in java that is supposed intentionally corrupt a file (specifically a .doc, txt, or pdf, but others would be good as well)
I initially tried this:
public void corruptFile (String pathInName, String pathOutName) {
curroptMethod method = new curroptMethod();
ArrayList<Integer> corruptHash = corrupt(getBytes(pathInName));
writeBytes(corruptHash, pathOutName);
new MimetypesFileTypeMap().getContentType(new File(pathInName));
// "/home/ephraim/Desktop/testfile"
}
public ArrayList<Integer> getBytes(String filePath) {
ArrayList<Integer> fileBytes = new ArrayList<Integer>();
try {
FileInputStream myInputStream = new FileInputStream(new File(filePath));
do {
int currentByte = myInputStream.read();
if(currentByte == -1) {
System.out.println("broke loop");
break;
}
fileBytes.add(currentByte);
} while (true);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(fileBytes);
return fileBytes;
}
public void writeBytes(ArrayList<Integer> hash, String pathName) {
try {
OutputStream myOutputStream = new FileOutputStream(new File(pathName));
for (int currentHash : hash) {
myOutputStream.write(currentHash);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(hash);
}
public ArrayList<Integer> corrupt(ArrayList<Integer> hash) {
ArrayList<Integer> corruptHash = new ArrayList<Integer>();
ArrayList<Integer> keywordCodeArray = new ArrayList<Integer>();
Integer keywordIndex = 0;
String keyword = "corruptthisfile";
for (int i = 0; i < keyword.length(); i++) {
keywordCodeArray.add(keyword.codePointAt(i));
}
for (Integer currentByte : hash) {
//Integer currentByteProduct = (keywordCodeArray.get(keywordIndex) + currentByte) / 2;
Integer currentByteProduct = currentByte - keywordCodeArray.get(keywordIndex);
if (currentByteProduct < 0) currentByteProduct += 255;
corruptHash.add(currentByteProduct);
if (keywordIndex == (keyword.length() - 1)) {
keywordIndex = 0;
} else keywordIndex++;
}
//System.out.println(corruptHash);
return corruptHash;
}
but the problem is that the file is still openable. When you open the file, all of the words are changed (and they may not make any sense, and they may not even be letters, but it can still be opened)
so here is my actual question:
Is there a way to make a file so corrupt that the computer doesn't know how to open it at all (ie. when you open it, the computer will say something along the lines of "this file is not recognized, and cannot be opened")?
I think you want to look into the RandomAccessFile. Also, it is almost always the case that a program recognizes its file by its very start. So open the file and scramble the first 5 bytes.
The only way to fully corrupt an arbitrary file is to replace all of its contents with random garbage. Even then, there is an infinitely small probability that the random garbage will actually be something meaningful.
Depending on the file type, it may be possible to recover from limited - or even from not so limited - corruption. E.g.:
Streaming media codecs are designed with network packet loss take into account. Limited corruption may show up as picture artifacts, or even as a few lost frames, but the content is usually still viewable.
Block-based compression algorithms, such as bzip2, allow undamaged blocks to be recovered.
File-based compression systems such as rar and zip may be able to recover those files whose compressed data has not been damaged, regardless of damage to the rest of the archive.
Human-readable text, such as text files and source code files, is still viewable in a text editor, even if parts of it are corrupt - not to mention its size that does not change. Unless you corrupted the whole thing, any casual reader would be able to tell whether an assignment was done and whether the retransmitted file was the same as the one that got corrupted.
Apart from the ethical issue, have you considered that this would be a one-time thing only? Data corruption does happen, but it's not that frequent and it's never that convenient...
If you are that desperate for more time, you would be better off breaking your leg and getting yourself admitted to a hospital.
There are better ways:
Your professor accepts Word documents. Infect it with a macro virus before sending.
"Forget" to attach the file to the email.
Forge the send date on your email. If your prof is the kind that accepts Word docs, this may work.
I am trying to communicate with Excel from a Java/SWT application. I have been able to open a worksheet, open a file and save it but that's about it.
Can anyone point me to some documentation/examples for this? I especially need to know which commands are available. I did try to record macros to inspect. This was useful but did not give me everything I wanted.
This is a sample of what I have been trying so far:
private static OleAutomation openFile(
OleAutomation automation, String fileName) {
Variant workbooks = automation.getProperty(0x0000023c);// get User
// Defined
// Workbooks
Variant[] arguments = new Variant[1];
arguments[0] = new Variant(fileName);
System.out.println("workbooks::\t" + workbooks);
IDispatch p1 = workbooks.getDispatch();
int[] rgdispid = workbooks.getAutomation().getIDsOfNames(new String[] { "Open" });
int dispIdMember = rgdispid[0];
Variant workbook = workbooks.getAutomation().invoke(dispIdMember, arguments);
System.out.println("Opened the Work Book");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
int id = workbook.getAutomation().getIDsOfNames(new String[] { "ActiveSheet" })[0];
System.out.println(id);
Variant sheet = workbook.getAutomation().getProperty(id);
OleAutomation sheetAutomation = sheet.getAutomation();
return (sheetAutomation);
}
Use VBA help MSOffice. Also you can use Object Browser in Office's VB editor.
Not a documentation, but since you asked about the available commands via automation: have you tried the OLE/COM Object viewer that comes with the Windows 2000 resource kit? Download here.