java

How to unpickle a file in Java?

旧街凉风 提交于 2021-02-18 19:45:15
问题 I have a 'pickle' format datafile that was created by a Python process (actually, the MCDungeon cache file). I want to read this from a Java program. To do this, I have used this code: public HashMap<String, Object> getDataFileStream(String filename) { HashMap<String, Object> data = new HashMap<String, Object>(); File f = new File(filename); InputStream fs = null; try { fs = new FileInputStream(f); } catch (FileNotFoundException e) { Log.warning("Pickle file '"+filename+"' not found!");

How to unpickle a file in Java?

半腔热情 提交于 2021-02-18 19:44:51
问题 I have a 'pickle' format datafile that was created by a Python process (actually, the MCDungeon cache file). I want to read this from a Java program. To do this, I have used this code: public HashMap<String, Object> getDataFileStream(String filename) { HashMap<String, Object> data = new HashMap<String, Object>(); File f = new File(filename); InputStream fs = null; try { fs = new FileInputStream(f); } catch (FileNotFoundException e) { Log.warning("Pickle file '"+filename+"' not found!");

Apache Http Client 4.0.1 SSL Proxy

好久不见. 提交于 2021-02-18 19:40:55
问题 I am using Apache Http client 4.0.1 for communicating with the server. I already have a secure/non secure client code that works just fine. Recently the new addition being to add proxy to this code, so i added the following piece of code to do that (currently non secure proxy), HttpHost proxy = new HttpHost("localhost", 5555); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); This has worked fine with a non secure request. However i am having trouble with a secure

Recording speakers Ouput using Java

拜拜、爱过 提交于 2021-02-18 19:34:35
问题 I want to ask the repetitive question of how to record the audio send to the speakers. But I want some insights to the previously answered. I went to this page: Capturing speaker output in Java I saw this code posted by a developer: import javax.sound.sampled.*; import java.io.*; public class JavaSoundRecorder { // record duration, in milliseconds static final long RECORD_TIME = 10000; // 1 minute // path of the wav file File wavFile = new File("E:/RecordAudio.wav"); // format of audio file

Comparison of enums values() method and class.getEnumConstants()

懵懂的女人 提交于 2021-02-18 19:33:38
问题 I'm trying to compare this two ways to achieving the enums values (with and without reflection). So this is my test class: public class ReflectionOnEnumsTests2 { enum TestEnum { ONE, TWO, THREE; } public static void main(String[] args) { long n = 600_000_000; int stub; //test without Reflection long timeStartWithoutReflection = System.currentTimeMillis(); for (int i = 0; i < n; i++){ TestEnum[] values = TestEnum.values(); stub = values.length; } System.out.println("Time consuming with

Java & XMLDSig: Reference with no URI

橙三吉。 提交于 2021-02-18 19:32:53
问题 I'm trying to sign some text using XMLDSig with javax.xml.crypto.dsig.* package. I need to make a reference to some content being signed. And according to project requirements this reference should not have any URI, it means not <Reference URI="">...</Reference>, but <Reference>...</Reference>. I haven't found any info whether it is possible and correct, but requirement says that XMLDSig allows such references, maximum one per signature. Have someone faced the same problem? What can be done

Java & XMLDSig: Reference with no URI

ぃ、小莉子 提交于 2021-02-18 19:32:08
问题 I'm trying to sign some text using XMLDSig with javax.xml.crypto.dsig.* package. I need to make a reference to some content being signed. And according to project requirements this reference should not have any URI, it means not <Reference URI="">...</Reference>, but <Reference>...</Reference>. I haven't found any info whether it is possible and correct, but requirement says that XMLDSig allows such references, maximum one per signature. Have someone faced the same problem? What can be done

run test classes from other path in testng.xml file

自古美人都是妖i 提交于 2021-02-18 19:31:34
问题 I am fairly beginner in TestNG, Maven & IntelliJ. I have created a new maven project and defined a 'runtest' class under src/main/java. I am able to run testcases through testng.xml if I specify test classes under src/main/java. However, I want to specify my test classes inside src/test/java. If I specify any test class 'test1.java' under src/test/java and run, it gives error : Error: Cannot find class in classpath: java/test1 Workarounds I already tried: In testng.xml file, giving full path

Comparing 2 JSONArray

北城以北 提交于 2021-02-18 19:27:28
问题 I have JSONArrays that needs to be compared which may have child entities inside it not in the same order though like this : [{ "A" : "IN", "B" : "DL"},{ "A" : "US", "B" : "KA"}] //JSONArray 1 [{ "A" : "US", "B" : "KA"},{ "A" : "IN", "B" : "DL"}] //JSONArray 2 Here is my code. Before calling JsonElemnt, I am converting both the JSONArray to String and then passing it to my function to compare : //Converting both JSONArray to String JsonArray1Str and JsonArray2Str JsonElement jsonElement1 =

How to re-use duplicate code with Enums in Java 8?

心已入冬 提交于 2021-02-18 19:26:07
问题 I have 3 enumerator classes in my application. All 3 classes have 2 duplicate methods that we want available in every enum that we implement. public static List<String> supported(){ return Arrays.asList([[EnumClass]].values()) .stream().map(Enum::name).collect(Collectors.toList()); } public static boolean contains(String value){ boolean response = false; try { response = value != null ? [[EnumClass]].valueOf(value.trim().toUppercase()) != null : false; } catch (Exception e){ LOGGER.error(