I recently used decode_qr from this FEX submission to decode my QR code. It ran quite well one or two weeks ago, but today it generate an error for me:
Undefined function or variable 'BufferedImageLuminanceSource'
Error in decode_qr (line 34);
source = BufferedImageLuminanceSource(jig);
I just checked the zxing repository and found that some files were updated several days ago. So I guess the path of some imported file from the package has been changed.
Here is the importing code from the decode_qr function:
import com.google.zxing.qrcode.*;
import com.google.zxing.client.j2se.*;
import com.google.zxing.*;
import com.google.zxing.common.*;
import com.google.zxing.Result.*;
How can I get it to work again? Do I need to change the import paths?
Here's what I did to get it to work (Win 10 x64, R2017b, ZXing 3.3.1):
Downloaded the latest prebuilt .jar artifacts from Sonatype:
core.
javase.
Added the files to my dynamic java classpath using javaaddpath:
javaaddpath('G:\core-3.3.1.jar');
javaaddpath('G:\javase-3.3.1.jar');
% Verify using: javaclasspath('-dynamic');
Note:
To add folders to the static path, which MATLAB loads at startup, create a javaclasspath.txt file, as described in Static Path.
Generated some example QR code using unitag.io:
Tried to decode it using Lior Shapira's decode_qr:
>> out = decode_qr(qr)
out =
'https://stackoverflow.com/users/3372061/dev-il'
Full code:
function out = q47223578()
javaaddpath('G:\core-3.3.1.jar');
javaaddpath('G:\javase-3.3.1.jar');
% Verify using: javaclasspath('-dynamic');
qr = imread('https://i.stack.imgur.com/mA4eP.png');
out = decode_qr(qr);
Related
The purpose of my project is to create PNG pictures from SVG using specific fonts (I have tried numerous converter services on the web but none of them worked with external fonts, and the JAVA program I have developed 10 years ago does no longer work).
My actual problem is the import of the batik.transcoder components into my program. Currently, it looks as follows:
<code>
// is this the really the parent of JPEGTranscoder / PNGTranscoder??
import javax.imageio.ImageTranscoder;
// Neither org.apache.batik... nor batik... is correct !!??
import org.apache.batik.transcoder.SVGAbstractTranscoder;
import batik.transcoder.TranscoderException;
import batik.transcoder.TranscoderInput;
import batik.transcoder.TranscoderOutput;
import batik.transcoder.PNGTranscoder;
import batik.transcoder.image.JPEGTranscoder;<br>
// or did I import the wrong jars ??
// (taken from batik-1.14 and afterwards from batik-1.7; neither did work!)
public class SVGConverter {
...
// all code lines below return the same error: "... cannot be resolved to a type"
TranscoderInput input = new TranscoderInput(svgURI);
TranscoderOutput output = new TranscoderOutput(ostream);
ImageTranscoder t;
...
t = new JPEGTranscoder();
...
t = new PNGTranscoder();
...
}
</code>
First I tried to import the batik components as modules on the module path but without success. In a contribution to stackoverflow I then found the hint to put the batik components not onto the module path but to the class path (Has batik not been converted into modules?). However, no success either.
I have copied all jar's contained in batik-1.14.zip and later of batik-1.7.zip into the lib directory within the project. No effect whatsoever...
I was using "import org.apache.batik.transcoder.XXX" in my previous program in 2013: Doesn't work any more. But using "import batik.transcoder.XXX" doesn't work either.
Thus, the following questions:
1. Is it correct that batik classes/jars have to be used via the class path?
2. What is the correct package name to address the respective packages and classes?
3. Is it correct to load the corresponding jar's into the lib directory of the project?
I am learning magnolia cms. I am trying to use the resources module. I have actually 2 problems.
Cannot upload a bunch of files. I have a few files, but in some time I will have to upload some more. Modules import feature wants me to upload an xml file. But I don't know how to generate it properly. Tried to import through JCR, but after that I can't see those files in resources app. Tried to configure the module to search files in file system: I set fileSystemLoader to class info.magnolia.module.resources.loaders.FileSystemResourceLoader and set some path. It did not work for me too. Maybe I just don't understand at what time should be activated files upload feature. At the application start up time it did not work.
How to properly use these resources in my template? What ftl tag should I use?
I don't use STK module.
Thanks for your patience if you decide to help me.
Magnolia version: 5.2 CE
JDK iced tea: 1.7.0_51
OS: Linux/OpenSUSE 12.3
I've used previously (on 4.5.x) script below to perform the task via groovy module. It should work on 5.2 as well.
import static groovy.io.FileType.FILES
import info.magnolia.jcr.util.NodeUtil
import org.apache.commons.lang.StringUtils
import info.magnolia.cms.util.ContentUtil
class Globals {
static def folderName = '//some/folder/in/filesystem/on/server'
}
def loadImageFolder() {
session = ctx.getJCRSession("resources")
parentFolder = session.getNode("/templating-kit/jelinek-image/obrazky-produkty")
new File(Globals.folderName).eachFileRecurse(FILES) {
name = it.name
// set file name
extension = StringUtils.substringAfterLast(name, '.')
name = StringUtils.substringBeforeLast(name, '.')
// persist
resource = NodeUtil.createPath(parentFolder,name , "mgnl:content")
// persistResource
resource.setProperty("mgnl:template", "resources:binary")
resource.setProperty("extension", extension)
binary = resource.addNode("binary", "mgnl:resource")
binary.setProperty("jcr:data", new FileInputStream(it.absolutePath))
binary.setProperty("extension", extension)
binary.setProperty("fileName", name)
binary.setProperty("jcr:mimeType", "image/"+extension)
binary.setProperty("size", it.length())
}
session.save()
}
loadImageFolder()
return 'done'
I've been searching for two days now trying to get PyDev to recognize my external .JAR (It's obfuscated for protection), however no matter what I do it doesn't want to work. I've read over the documentation for nearly a hour straight trying to get it to work.
I'm helping to work on an emulation server which uses Jython for scripting. I can compile and run the emulation server with the scripts working just fine however, without using autocompletion for the methods inside the engine part of the server which is obfuscated in a external .jar.
Here is an example code of a script which uses methods from the obfuscated .JAR (which isn't working with autocomplete, so I have to navigate through the package explorer to find the method I want to use):
import sys
def CreateStartingCharacter(core, object):
testObject = core.objectService.createObject('object/weapon/ranged/rifle/shared_rifle_t21.iff', object.getPlanet())
testObject.setCustomName('This is a Jython Rifle')
testObject.setStringAttribute('crafter', 'Light')
inventory = object.getSlottedObject('inventory')
inventory.add(testObject)
testClothing = core.objectService.createObject('object/tangible/wearables/cape/shared_cape_rebel_01.iff', object.getPlanet())
testClothing.setCustomName('Test Cape')
testCloak = core.objectService.createObject('object/tangible/wearables/robe/shared_robe_jedi_dark_s05.iff', object.getPlanet())
testCloak.setCustomName('Test Cloak')
inventory.add(testClothing)
inventory.add(testCloak)
return
This script is executed by the following command in Java (core is the class inside the external JAR, obfuscated)
core.scriptService.callScript("scripts/", "demo", "CreateStartingCharacter", object);
object is...
CreatureObject object = (CreatureObject)core.objectService.createObject(sharedRaceTemplate, core.terrainService.getPlanetList().get(0));
Like I said above, all of those methods that I used in the script were from the obfuscated JAR which isn't working with autocomplete. However, I can use a method that isn't in that JAR just fine such as:
from resources.common import RadialOptions
from services.sui import SUIWindow
from services.sui.SUIWindow import Trigger
from java.util import Vector
import sys
def createRadial(core, owner, target, radials):
radials.clear()
bank = owner.getSlottedObject('bank')
if bank:
radials.add(RadialOptions(0, 21, 1, ''))
radials.add(RadialOptions(0, 7, 1, ''))
radials.add(RadialOptions(1, RadialOptions.bankTransfer, 3, '#sui:bank_credits'))
radials.add(RadialOptions(1, RadialOptions.bankitems, 3, '#sui:bank_items'))
if owner.getBankCredits() > 0:
radials.add(RadialOptions(1, RadialOptions.bankWithdrawAll, 3, '#sui:bank_withdrawall'))
if owner.getCashCredits() > 0:
radials.add(RadialOptions(1, RadialOptions.bankDepositAll, 3, '#sui:bank_depositall'))
return
... and using RadialOptions. control+space will show me all the methods.
Help would be much appreciated. At this point I feel that it's not working because the JAR file is obfuscated or something like that. And yes, I've already added it to my PYTHONPATH and updated the interpreter, just like with the bin folder for my project.
I'm attempting to use JPype to call Apache Pdfbox from Python, and am having some difficulty actually importing the classes. It doesn't seem to be able to read them from the jar file in the class path.
from jpype import java, startJVM, shutdownJVM, JPackage, JClass, getDefaultJVMPath, nio
import sys, os, codecs
pdfbox_lib = "lib/pdfbox-1.6.0.jar"
classpath = '-Djava.class.path=' + pdfbox_lib + os.pathsep + '.'
startJVM(getDefaultJVMPath(), '-Xmx512m', classpath)
stream = java.io.FileInputStream(java.io.File("test.pdf"))
pdfparser = JPackage('org.apache.pdfbox.pdfparser')
parser = JClass('org.apache.pdfbox.pdfparser.PDFParser')
At this point, the script errors out with the following:
java.lang.ExceptionPyRaisable: java.lang.Exception: Class org.apache.pdfbox.pdfparser.PDFParser not found
I'm running on Linux with Python 2.7, and I know there's nothing wrong with the JPype installation (if there were, the stream declaration would error out). I've also tried various permutations of the class path statement and the JPackage/JClass statements, and nothing seems to matter. Any suggestions would be greatly appreciated!
I figured it out. Three additional jars need to be added to the class path: fontbox-x.x.x.jar, jempbox-x.x.x.jar, and commons-logging.jar.
For this two imports;
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
I got this error:
Access restriction: The type BASE64Decoder is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar
How can I resolve this error?
Go to Window-->Preferences-->Java-->Compiler-->Error/Warnings.
Select Deprecated and Restricted API. Change it to warning.
Change forbidden and Discouraged Reference and change it to warning. (or as your need.)
That error is caused by your Eclipse configuration. You can reduce it to a warning. Better still, use a Base64 encoder that isn't part of a non-public API. Apache Commons has one, or when you're already on Java 1.8, then use java.util.Base64.
Sure - just don't use the Sun base64 encoder/decoder. There are plenty of other options available, including Apache Codec or this public domain implementation.
Then read why you shouldn't use sun.* packages.
Java 6 ships the javax.xml.bind.DatatypeConverter. This class provides two static methods that support the same decoding & encoding:
parseBase64Binary() / printBase64Binary()
Update:
Since Java 8 we now have a much better Base64 Support.
Use this and you will not need an extra library, like Apache Commons Codec.
I had this problem on jdk1.6.0_37.
This is the only JDE/JRE on my system. I don't know why, but the following solved the problem:
Project -> Properties -> Java Build Path - > Libraries
Switch radio button from Execution environment to Alernate JRE.
This selects the same jdk1.6.0_37, but after clean/build the compile error disappeared.
Maybe clarification in answer from ram (Mar 16 at 9:00) has to do something with that.
Yup, and sun.misc.BASE64Decoder is way slower: 9x slower than java.xml.bind.DatatypeConverter.parseBase64Binary() and 4x slower than org.apache.commons.codec.binary.Base64.decodeBase64(), at least for a small string on Java 6 OSX.
Below is the test program I used. With Java 1.6.0_43 on OSX:
john:password = am9objpwYXNzd29yZA==
javax.xml took 373: john:password
apache took 612: john:password
sun took 2215: john:password
Btw that's with commons-codec 1.4. With 1.7 it seems to get slower:
javax.xml took 377: john:password
apache took 1681: john:password
sun took 2197: john:password
Didn't test Java 7 or other OS.
import javax.xml.bind.DatatypeConverter;
import org.apache.commons.codec.binary.Base64;
import java.io.IOException;
public class TestBase64 {
private static volatile String save = null;
public static void main(String argv[]) {
String teststr = "john:password";
String b64 = DatatypeConverter.printBase64Binary(teststr.getBytes());
System.out.println(teststr + " = " + b64);
try {
final int COUNT = 1000000;
long start;
start = System.currentTimeMillis();
for (int i=0; i<COUNT; ++i) {
save = new String(DatatypeConverter.parseBase64Binary(b64));
}
System.out.println("javax.xml took "+(System.currentTimeMillis()-start)+": "+save);
start = System.currentTimeMillis();
for (int i=0; i<COUNT; ++i) {
save = new String(Base64.decodeBase64(b64));
}
System.out.println("apache took "+(System.currentTimeMillis()-start)+": "+save);
sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
start = System.currentTimeMillis();
for (int i=0; i<COUNT; ++i) {
save = new String(dec.decodeBuffer(b64));
}
System.out.println("sun took "+(System.currentTimeMillis()-start)+": "+save);
} catch (Exception e) {
System.out.println(e);
}
}
}
This error is because of you are importing below two classes
import sun.misc.BASE64Encoder; import sun.misc.BASE64Decoder;. Maybe you are using encode and decode of that library like below.
new BASE64Encoder().encode(encVal);
newBASE64Decoder().decodeBuffer(encryptedData);
Yeah instead of sun.misc.BASE64Encoder you can import
java.util.Base64 class.Now change the previous encode method as below:
encryptedData=Base64.getEncoder().encodeToString(encryptedByteArray);
Now change the previous decode method as below
byte[] base64DecodedData = Base64.getDecoder().decode(base64EncodedData);
Now everything is done , you can save your program and run. It will run without showing any error.
Go to the Build Path settings in the project properties.
Remove the JRE System Library
Add it back; Select "Add Library" and select the JRE System Library. The default worked for me.
This works because you have multiple classes in different jar files. Removing and re-adding the jre lib will make the right classes be first. If you want a fundamental solution make sure you exclude the jar files with the same classes.
Be careful, sun.misc.BASE64Decoder is not available in JDK-13
This error (or warning in later versions) occurs because you are compiling against a Java Execution Environment. This shows up as JRE System library [CDC-1.0/Foundation-1.0] in the Build path of your Eclipse Java project. Such environments only expose the Java standard API instead of all the classes within the runtime. This means that the classes used to implement the Java standard API are not exposed.
You can allow access to these particular classes using access rules, you could configure Eclipse to use the JDK directly or you could disable the error. You would however be hiding a serious error as Sun internal classes shouldn't be used (see below for a short explanation).
Java contains a Base64 class in the standard API since Java 1.8. See below for an example how to use it:
Java 8 import statement:
import java.util.Base64;
Java 8 example code:
// create a byte array containing data (test)
byte[] binaryData = new byte[] { 0x64, 0x61, 0x74, 0x61 };
// create and configure encoder (using method chaining)
Base64.Encoder base64Encoder = Base64.getEncoder().withoutPadding();
// encode to string (instead of a byte array containing ASCII)
String base64EncodedData = base64Encoder.encodeToString(binaryData);
// decode using a single statement (no reuse of decoder)
// NOTE the decoder won't fail because the padding is missing
byte[] base64DecodedData = Base64.getDecoder().decode(base64EncodedData);
If Java 8 is not available a library such as Apache Commons Codec or Guava should be used.
Sun internal classes shouldn't be used. Those classes are used to implement Java. They have got public methods to allow instantiation from other packages. A good build environment however should protect you from using them.
Using internal classes may break compatibility with future Java SE runtimes; the implementation and location of these classes can change at any time. It should be strongly discouraged to disable the error or warning (but the disabling of the error is suggested in previous answers, including the two top voted ones).
I am using unix system.
In eclipse project-> Properties -> Java Compiler -> Errors/Warning -> Forbidden Access(access rule) -> Turn it to warning/Ignore(Previously it was set to Error).
Was getting sun.misc.base64encoder cannot be resolved to a type on eclipse -
Resolved this by pointing eclipse to use Java version 1.8 installed on system -
Windows -> Preferences -> Java -> Installed JREs -> add jre path (eg: C:\Program Files\Java\jdk1.8.0_271)
Right-click on project -> Maven -> Update project
This will resolve then.
I know this is very Old post. Since we don't have any thing sun.misc in maven
we can easily use
StringUtils.newStringUtf8(Base64.encodeBase64(encVal));
From org.apache.commons.codec.binary.Base64
solution: go into java 8 sdk fodler, from jre\lib\rt.jar copy to sdklib.jar (it is somewhere in eclipse folder) classes (with same paths):
sun/misc/BASE64Decoder.class,
sun/misc/BASE64Encoder.class,
sun/misc/CharacterDecoder.class,
sun/misc/CharacterEncoder.class
that's all
Add base64decoder jar and try these imports:
import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;