java - parsing custom file by tag - java

I have a file formated .TXT like this :
[Quest]
Name: The Adventure
Creator: Darius
Reward: 0g
[#New Monster]
MonsterID: 100
MonsterHP: 23987
MonsterLv: 11
MonsterDmg: 133
MonsterType: Magic
[#New Monster]
MonsterID: 101
MonsterHP: 21236
MonsterLv: 8
MonsterDmg: 95
MonsterType: Physical
[#New Item]
ItemID: 222
ItemDamage: 88
ItemType: Robe
How can i parse this file so i can get the monsterid,monsterhp etc and itemId,itemdamage etc. There is two [#New Monsters]

Related

Buffered Writer occasionally creates symbols rather than numbers

So I have a program that collects a bunch of data and continuously concatenates the data into a string with a single white space between each entry. During my close routine I print the String into a txt file using buffered writer. About 50% of the time the data shows up as (mostly) Chinese symbols. Is the VM doing some weird Unicode stuff? Why does this only occur sometimes?
I've looked around on other forums and have not seen other instances of this problem. None of the other CS majors I know understand what is happening.
EDIT : the data is all integer numbers ranging 0-1365;
UPDATE: upon further research I found this which makes me think a may need a PrintStream rather than a BufferedWriter can anyone speak to that? I tested the PrintStream and I will not be able to construct it with a FileWriter as I would a BufferedWriter which means I need more research to write to my txt.
UPDATE: printing to the console does not make this error occur. I will accept an answer that explains way Notepad (the program I am using to open the txt) sometimes displays numbers and sometimes displays symbols.
Here is the relevant code:
//fields
private static BufferedWriter out;
private File saveFile;
String data;
//inside constructor
this.saveFile = new File("C:\\Users\\HPlaptop\\Desktop\\MouseData.txt");
this.saveFile.delete();
try{this.saveFile.createNewFile();}
catch (IOException e ){System.out.println("File creation error");}
try {out = new BufferedWriter(new FileWriter("C:\\Users\\HPlaptop\\Desktop\\MouseData.txt"));}
catch (IOException e) {System.out.println("IO Error");}
this.control.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ //there is a method call here but the basics are below
out.write(data);
out.close();
System.exit(0);
}
});
Here is an example data set printed correctly:
1365 767 1365 767 1365 767 1364 767 1353 756 1268 692 1114 604 980 488 812 334 744 283 694 244 593 150 473 81 328 13 207 0 124 0 115 0 102 0 99 6 107 13 132 20 173 32 187 31 190 25 194 20 201 17 215 14 221 10 224 7 224 7 224 7 226 6 226 6 226 6 226 6 226 6 226 6 226 6
This data set was taken seconds later and is not what I want
㐀ㄹ㈠㤰㐠㔸㈠㈱㐠㠶㈠㐱㐠㘲㈠㘰㌠㠷ㄠ㔹㌠㌳ㄠ㌹㈠㘹㈠㄰㈠㠷㈠㜳㈠㐶㈠㐷㈠㐶㈠㔷㈠㌶㈠㔵㈠㐵㈠㠰㈠㤴ㄠ㔲㈠㤴㐠‶㐲‹㌱㈠㘴〠㈠㘴〠㈠㘴〠㈠㜴〠㈠㠴〠㈠㠴〠㈠㜴㠠㈠㔴ㄠ‶㐲‵㤱㈠㔴ㄠ‹㐲‵㠱㈠㜴ㄠ‶㐲‹ㄱ㈠〵ㄠ‰㔲‰〱
The BufferedWriter is not making an error and the code is correct except for
the redundancy of using
this.saveFile.delete();
try{this.saveFile.createNewFile();}
catch (IOException e ){System.out.println("File creation error");}
and
new FileWriter
The error in reading the data occurs when the file is opened. The depending on what program opens the data different results are displayed because of the way the software reads the data. Notepad was displaying symbols because it interpreted the numbers as ASCII. The console did not try to interpret the data and just displayed what was written to it. Using a program that does not try to interpret the numbers in the file will allow the data to be viewed correctly.
Since you did not provide and example of what data you write into the stream, you are probably experiencing the bush hid the facts phenomenon.

Convert binary file data to normal .txt

I recently formatted my hard drive and forgot to save a java project from it. After trying to recover those files with recovery tools found on internet, I got the files back but... the content is unreadable; i.e. my Main.java class looks like :
108b 4424 5085 ff8b 403c 7e10 8b7c 2410
8904 2489 7c24 04e8 74b0 0200 8b74 2428
8d45 07c7 4424 2000 0000 0089 4424 1885
f60f 8e52 0100 0090 8b44 2450 8b7c 2420
8b4c 2410 8b40 1885 c98b 04b8 8944 2424
8b44 2450 8b40 248b 3cb8 8b44 2450 8b40
3c89 4424 1c0f 8e3d 0100 0031 f631 ed89
7c24 2c89 f7eb 0e90 c604 2f00 83c5 013b
6c24 1074 3f39 f57c ef8b 4424 1c8d 7436
0189 7424 0489 0424 e8f3 af02 0089 6c24
0889 7c24 0489 0424 8944 2414 e86f a202
...
What is this exactly? Is there a way I can write like a python script to translate it back to a readable java class ? Simple hexadecimal to ascii doesn't seem to work.

Java xml parsing. Navigating deep inside in a xml file with one function call

I have the following xml file
<basicCallInformation>
<chargeableSubscriber>
<simChargeableSubscriber>
<imsi>26 20 32 23 16 62 80 3F</imsi>
<msisdn>49 16 32 70 04 00</msisdn>
</simChargeableSubscriber>
</chargeableSubscriber>
</basicCallInformation>
I would like to go directly to the nodes "imsi" and "msisdn" to obtain their values with one function call if possible. Something like this
basicCallInformationNode.getNode('chargeableSubscriber/simChargeableSubscriber/imsi'); //something like this can be done in PLSQL
Is there a way to do that in Java? any workaround?
P.S. I am using DOM parser
Sure,
XPath.evaluate(
"/basicCallInformation/chargeableSubscriber/simChargeableSubscriber/imsi |
/basicCallInformation/chargeableSubscriber/simChargeableSubscriber/msisdn"
);

Android build error: ro.build.fingerprint cannot exceed 91 bytes

I'm building an android rom from the android source code but after about 5 minutes it gives this error.
error: ro.build.fingerprint cannot exceed 91 bytes: Android/mini_emulator_x86/mini-emulator-x86:5.0.555/AOSP/username02280306:userdebug/test-keys (97)
make: *** [out/target/product/mini-emulator-x86/system/build.prop] Error 1
make: *** Deleting file `out/target/product/mini-emulator-x86/system/build.prop'
make: *** Waiting for unfinished jobs....
How do I increase the ro.build.fingerprint size limit?
Plus I'm building on a Mac.
Edit build/tools/post_process_props.py. Change lines as follows:
PROP_NAME_MAX = 31
# PROP_VALUE_MAX = 91
PROP_VALUE_MAX = 128
Edit bionic/libc/include/sys/system_properties.h. Change lines as follows:
#define PROP_NAME_MAX 32
// #define PROP_VALUE_MAX 92
#define PROP_VALUE_MAX 128
Do
make clean
make
You can also run the second make command in parallel using syntax such as
make -j8
Alternatively, you can specify the build fingerprint string as command line argument to make using:
make -j5 BUILD_FINGERPRINT="....."
This will allow you to stay within the 91 byte limit.

java profile tool without gui

Is there a java profile tool that works without a GUI in Linux, just like top? I don't have the permission to use tools like jprofile and jvisualvm to work in remote model.
Try this: http://java.sun.com/developer/technicalArticles/Programming/HPROF.html You can query heap and cpu details.
You can use HPROF.
Command used: javac -J-agentlib:hprof=cpu=samples Hello.java
CPU SAMPLES BEGIN (total = 126) Fri Oct 22 12:12:14 2004
rank self accum count trace method
1 53.17% 53.17% 67 300027 java.util.zip.ZipFile.getEntry
2 17.46% 70.63% 22 300135 java.util.zip.ZipFile.getNextEntry
3 5.56% 76.19% 7 300111 java.lang.ClassLoader.defineClass2
4 3.97% 80.16% 5 300140 java.io.UnixFileSystem.list
5 2.38% 82.54% 3 300149 java.lang.Shutdown.halt0
6 1.59% 84.13% 2 300136 java.util.zip.ZipEntry.initFields
7 1.59% 85.71% 2 300138 java.lang.String.substring
8 1.59% 87.30% 2 300026 java.util.zip.ZipFile.open
9 0.79% 88.10% 1 300118 com.sun.tools.javac.code.Type$ErrorType.<init>
10 0.79% 88.89% 1 300134 java.util.zip.ZipFile.ensureOpen

Categories

Resources