Java YAML Reader

I have a java program written which has to read a configuration file written using YAML (config.yml)
I downloaded the yamlbeans-1.0.jar from http://yamlbeans.sourceforge.net/ which has the YamlReader class I am using in my java program. And I then copied the YamlReader.class file to the folder where I have my Testing.java program.
Please find my java and config.yml files below.
//JAVA FILE
class Testing
public static void main(String args[]) throws Exception
YamlReader reader = new YamlReader(new FileReader("config.yml"));
Object object = reader.read();
System.out.println(object);
Map map = (Map)object;
System.out.println(map.get("NAME"));
//YAML file
NAME: mail.foobar.net
EMAIL_ADDRESS: [email protected]
AGE: 15
when I try to compile the java file, I get the following error.
C:\Users\David\Desktop\webstat\Testing.java:11: cannot access YamlReader
bad class file: .\YamlReader.class
class file contains wrong class: net.sourceforge.yamlbeans.YamlReader
Please remove or make sure it appears in the correct subdirectory of the classpath.
YamlReader reader = new YamlReader(new FileReader("config.yml"));
^
1 error
Tool completed with exit code 1
Can some one please suggest me what has to be done to get YamlReader accessible in my program.
Thanks!

Normally, you don't extract class files from a jar file. You just stick the whole jar file in the classpath. Like this, for example:
javac -classpath TheJar.jar MyProgram.javaSecond, YamlReader seems to be in the package net.sourceforge.yamlbeans.YamlReader.
So you wouldn't just dump YamlReader.class in the current directory; if you were to unpack it from the jar (which you shouldn't), you'd have to put it in a directory that reflected the package structure. And then you'd have to refer to the class with its full path name, or use an import statement.
You should probably read a few introductory Java tutorials before proceeding.
[add]
Damned crossposter.
Thanks for wasting my time, jerk!
Edited by: paulcw on Dec 4, 2009 12:37 PM

Similar Messages

  • Java.io.Reader to String conversion

    I am working on a SOAP project with Jaxm and I retreive the result as a Reader, but I need to convert it into a String.
    I did the following code but it is incredibely slow with a big reply (280kb) as I retrieve each character one after each other.
    Does a faster solution exist ?
    // Soap call
    SOAPMessage reply = m_conn.call(message, endpoint);
    java.util.Iterator it = reply.getAttachments();
    // First attachment returned by the server hold my result
    AttachmentPart resultAttachment = (AttachmentPart) it.next();
    StreamSource resultStreamSource = (StreamSource) resultAttachment.getContent();
    // Converts java.io.Reader to String
    java.io.Reader resultReader = resultStreamSource.getReader();
    String result = "";
    int charValue = 0;
    while ((charValue = resultReader.read()) != -1) {
       result = result + (char) charValue;

    use a BufferedReader and create a large char[] (64k or something)
    then use
    char[] cbuf = new char[65536];
    StringBuffer stringbuf = new StringBuffer();
    int read_this_time = 0;
    while (read_this_time != -1) {
    read_this_time = BufferedReader.read(cbuf,0,65536);
    stringbuf.append(cbuf,0,read_this_time);
    }//end while
    StringBuffer is faster than String concatenation because when java concatenates strings it creates a new object every time. StringBuffer just stores and appends the string without creating new objects.

  • Java.io.Reader - java.io.InputStream

    Hi!
    Is there a way to wrap a java.io.Reader into an java.io.InputStream (like java.io.InputStreamReader does but in the other direction)?
    I found now class doing this job (deduced from java.io.InputStream, taking an java.io.Reader as Constructor Parameter) :-/
    If I want to write my own wrapper I've got two problems:
    * If I want to read data I have to split the char which I read from the wrapped java.io.Reader into a high and a low byte and than return two values.
    * But if I want to read text I can't just split the char into two bytes but I have to convert it
    How can I solve this problem?

    Is there a way to wrap a java.io.Reader into an java.io.InputStream (like java.io.InputStreamReader does but in the other direction)?Why don't you explain what the real problem is? I suspect that there's a solution, but you need to state it. What was the creator and source of the information (file?) that you're trying to read that contains "data" and, apparently, Java characters in a different charset?

  • Java.io.Reader byte2char conversion???

    Hi!
    What encoding java.io.Reader uses to convert read bytes to chars?
    What to do if I need to read several text files written in different encodins?
    It seems that readers use default OS encoding to read text files and changing of default Locale doesn't take any effect. Is there any method to change the default encoding for readers?
    Anton

    What encoding java.io.Reader uses to convert read
    bytes to chars?It depends on the Reader. The usual choice is some default based on your system.
    What to do if I need to read several text files
    written in different encodins?
    It seems that readers use default OS encoding to read
    text files and changing of default Locale doesn't take
    any effect. Is there any method to change the default
    encoding for readers?You use an InputStreamReader, which allows you to specify the encoding. RTFM for more details.

  • How to read BLOBs as "Java.io.Reader"

    Hello,
    I have a problem dealing with BLOBs in JDBC. I want to get a BLOB as a "java.io.Reader". I have written the following code:
    class Db_templates {
    public static Reader select(int tpl_id) {
    try {
    Connection connection = ... ;
    Reader retour = null;
    String strSQL = "SELECT tpl_blob FROM templates WHERE tpl_id = ?";
    PreparedStatement ps = connection.prepareStatement(strSQL);
    ps.setInt(1, tpl_id);
    ResultSet rset = ps.executeQuery();
    if (rset.next()) {
    oracle.sql.BLOB blob = (BLOB)rset.getObject(1);
    retour = blob.characterStreamValue();
    rset.close();
    ps.close();
    connection.close();
    return retour;
    } catch (SQLException e) {
    return null;
    Then I try to call this method in a JSP file (Tomcat 4.0 as JSP container) with the following lines:
    Reader i = Db_templates.select(42);
    out.println(i.ready());
    char buf[] = new char[1000];
    try {
    int retour = i.read(buf, 1, 900);
    } catch (IOException e) {
    out.println(e.toString());
    The method i.ready() returns false with no IOException thrown.
    The method i.read() fails to execute with the following errors:
    java.lang.NullPointerException
    at oracle.sql.LobPlsqlUtil.plsql_read(LobPlsqlUtil.java:911)
    at oracle.sql.LobPlsqlUtil.plsql_read(LobPlsqlUtil.java:52)
    at oracle.jdbc.dbaccess.DBAccess.lobRead(DBAccess.java:658)
    at oracle.sql.LobDBAccessImpl.getBytes(LobDBAccessImpl.java:95)
    at oracle.sql.BLOB.getBytes(BLOB.java:175)
    at oracle.jdbc.driver.OracleBlobInputStream.needBytes(OracleBlobInputStream.java:126)
    at oracle.jdbc.driver.OracleBufferedStream.read(OracleBufferedStream.java:108)
    at oracle.jdbc.driver.OracleConversionReader.needChars(OracleConversionReader.java:151)
    at oracle.jdbc.driver.OracleConversionReader.read(OracleConversionReader.java:119)
    at org.apache.jsp.essai2$jsp._jspService(essai2$jsp.java:87)
    Any ideas?
    Thanks,
    Nicolas

    Normally, Firefox has two different behaviors for the down arrow key, assuming it is not inside a form control:
    * Scroll the page
    * With caret browsing turned on, move the cursor down one line
    If you are accustomed to the down arrow key moving among search results so you can press the Enter key to load them, and you are using Google, this is due to a script in the results page intercepting those keys and changing what they normally do.
    I have only tested Windows myself, so I don't know whether this is generally available when using Google in your distribution of Linux. If it is, then the question would be: why not on your Firefox? Hmm...

  • Can't convert FileReader to java.io.Reader

    Hi
    I have a code segment that generates error during compilation of the source file: "Incompatible type for constructor. Can't convert FileReader to java.io.Reader.
         buffVideo = new BufferedReader (file)
         ^
    The code segment is:
    FileReader file;
    BufferedReader buffVideo;
    StreamTokenizer tokenVideo;
    String s;
    try {
         file = new FileReader (fileVideo);
         buffVideo = new BufferedReader (file);
         tokenVideo = new StreamTokenizer (buffVideo);
    import java.io.* is at the top of the .java file. It is a part of a definition of a new class. fileVideo is a String variable containing file name of a text file.
    Exactly the same .java source file compiles on a Windows 98 based machine, but not on a Windows 2000 Professional. I use version 1.1.6 as it is required by my current course.
    Can anybody suggest any resoultion for this problem, please?
    Thanks in advance

    Branko,
    Wow, my ID still works. Amazing, I haven't visited for years.
    Ged Byrne writes:
    Branko,
    This is a realy puzzler. My only guess is that you have a namespace
    conflict. The error message states:
    Can't convert File Reader to java.io.Reader
    It seems that there is another class called FileReader that is clashing
    with the on in java.io.
    Have you inadvertantly named something FileReader yourself?
    Perhaps your classpath is including something that contains a FileReader.
    Try declaring file as java.io.FileReader rather than just FileReader.
    I'm clutching at straws.
    Ged.

  • Cost of Java Card, Reader, Tools etc

    Hello All..
    I could see old data about cost of Java Card, Reader, tools etc discussed way back in feb 2006..
    Does any one have recent cost data who can share here.
    Like to know approximate cost that i should incur to buy Java Card, Reader, associated tools,IDE etc.
    it would be nice to discuss about vendor details and cost of the product they offer.
    thanks

    The major factor in determining cost is quantity. The more u want, the cheaper they cost. For developer cards, manufacturers already have them "on the shelf" so there's no manufacturing cost involved. But as you move to real-world deployment, then you start getting a different cost model. Then issues of applets, card management systems, infrastructure start to affect the cost of a card. I've had a business model that made the total price of one 32k java card cost $100 due to those factors.
    As far as readers go, it's different. Assuming you want desktop readers, you need to deal with issues of lost readers, PCMCIA or USB. Most deployments I've dealt with went with USB so they are portable to multiple hardware.
    Assuming you mean development tools, JCOP is the king so far. For deployment tools, well that's expensive mainly because the players use a closed proprietary solution. Also, if you are doing PKI deployments, then you'll need a CA and then HSMs come into play and that just recks havoc on costing !!!!!
    Happy Deployment !!!!!

  • Need official interpretation - java.io.Reader read(char[] cbuf) method

    Hello Everyone,
    I need Sun API's official interpretation on java.io.Reader read(char[] cbuf) method;
    Say, I provide this read method a char[] of size 8096, could the implementing class return even before reading into the whole buffer array? Say, the implementing class just reads 1024 chars and return 1024 as the method output, has the implementing class fulfilled its obligation?
    In my mind, the read method should attempt to read and fill the buffer array until of course i/o error occurs or end of stream is reached? See BufferedReader source for this type of implementation.
    Or could the read method just attempt to read into the buffer (with no obligation) and can return before completely filling the buffer?
    Sincere Regards.

    This is the situation: (and we are caught in between arbitrating on whom to ask to make the fix)
    Please note that I am not taking any names here, but remember these vendors are the biggest in their market.
    Vendor Db A has an API wherein it returns a stream and its length;
    Vendor B consumers this API via the java.io.Reader class as follows:
    char[] data = new char[(int) VendorAStream.length()];
    VendorAStream.read(data);
    Vendor B contends that per java.io.Reader API, it is responsibility of Vendor A to implement the read method correctly!!! (which is to read the data completely, not partially); Vendor B further contends that their code works fine with all the other Db vendors (except Vendor A); [Quite *tupid reasoning in my mind ;-) ]
    Vendor A says per java API, we can partially fill the buffer (they are specifically only reading 1024 chars from the stream)
    Initially, I thought, Vendor B must fix the code to handle partial reads. But no where it is mentioned clearly that Reader.read only attempts to read the chars and can return before filling the buffer.
    Dannyyates,
    (*My interpretation*) The reason it says "*maximum* number of characters to read" is for the situation when end of stream is reached before fully filling the buffer. In that case, the length of buffer and number of actually chars read wont match. This explanation covers for your observation (c)
    BIJ001, No problem in your explanation. I understand and I am merely pointing you to alternate interpretation of the API.
    Please comment. Thanks for your time to discuss this.
    Sincere Regards.

  • How to NOT ignore java beans read only properties when serializing Java to AS?

    As stated in the Adobe LCDS documentation, the read-only properties of a java bean are ignored in the AMF serialization process.
    Would you know what to do so that Java beans read only properties do not get discarded when sending it via BlazeDS AMF?
    Many thanks in advance.

    Hi,
    I've managed to get what I needed by using a shift register + event structure as suggested by Adnan. However, I face another problem after implementing SR+event. I've attached two files, first the original program and second the updated program using SR + event. (it's only the jpg file as I've forgotten to save the labview program, will upload the program by tomorrow.
    In the original program, I have an elapsed time that is able to run continuously when I run the program. In the updated program, my elapsed time don't seem to run continuously when I run the program (as shown by elapsed time indicator). I need the elapsed time to run continuously as a input to calculate my motor profile.
    I suppose this is caused by the introduction of the event structure, will adding a case structure to wrap the event structure solve the problem or is there another way to get pass this. Appreciate if someone could drop me a pointer or two.
    Thanks
    Attachments:
    Mar 16 - continuous elapsed time.png ‏12 KB
    Mar 16 - elapsed time not continuous after introducing shift register + event structure.png ‏17 KB

  • How to get return value from java and read by other application?

    i want to read return value from java and the other application read it.
    for example:
    public class test_return {
        test_return(){
        public int check(){
            return 1;
        public static void main(String args[]){
           new test_return().check();
    }from that class i make as jar file. How to read the return value (1) by other application?
    thx..

    If your installer is requiring some process it invokes to return a particular value on failure, then the installer is seriously broken. There are a bazillion commands your installer could invoke, and any of them could fail, which in turn could invalidate the entire install process, and any of them could return any value on failure. The only value that's consistent (in my experience) is that zero means success and non-zero means failure, with specific non-zero values being different in different programs.
    About the only control you have over the JVM's exit code is that if your main method completes without throwing an exception, the JVM will have an exit code of 0, and if main throws an exception (either explicitly or by not catching one thrown from below), it will be non-zero. I'm not even sure if that's guaranteed, but I would guess that's the case.
    EDIT: I'm kind of full of crap here. If you're writing the Java code, you can call System.exit(whatever). But nonetheless, if your installer requires certain exit codes from any app--java or otherwise--you have a problem.
    Edited by: jverd on Oct 29, 2009 1:27 AM

  • Where does this java program read a text file and how does it output the re

    someone sent this to me. its a generic translator where it reads a hashmap text file which has the replacement vocabulary etc... and then reads another text file that has what you want translated and then outputs translation. what i don't understand is where i need to plugin the name of the text files and what is the very first line of code?
    [code
    package forums;
    //references:
    //http://forums.techguy.org/development/570048-need-write-java-program-convert.html
    //http://www.wellho.net/resources/ex.php4?item=j714/Hmap.java
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class Translate {
    public static void main(String [] args) throws IOException {
    if (args.length != 2) {
    System.err.println("usage: Translate wordmapfile textfile");
    System.exit(1);
    try {
    HashMap words = ReadHashMapFromFile(args[0]);
    System.out.println(ProcessFile(words, args[1]));
    } catch (Exception e) {
    e.printStackTrace();
    // static helper methods
    * Reads a file into a HashMap. The file should contain lines of the format
    * "key\tvalue\n"
    * @returns a hashmap of the given file
    @SuppressWarnings("unchecked")
    private static HashMap ReadHashMapFromFile(String filename) throws FileNotFoundException, IOException {
    BufferedReader in = null;
    HashMap map = null;
    try {
    in = new BufferedReader(new FileReader(filename));
    String line;
    map = new HashMap();
    while ((line = in.readLine()) != null) {
    String[] fields = line.split("\\t", 2);
    if (fields.length != 2) continue; //just ignore "invalid" lines
    map.put(fields[0], fields[1]);
    } finally {
    if(in!=null) in.close(); //may throw IOException
    return(map); //returning a reference to local variable is safe in java (unlike C/C++)
    * Process the given file
    * @returns String contains the whole file.
    private static String ProcessFile(Map words, String filename) throws FileNotFoundException, IOException {
    BufferedReader in = null;
    StringBuffer out = null;
    try {
    in = new BufferedReader(new FileReader(filename));
    out = new StringBuffer();
    String line = null;
    while( (line=in.readLine()) != null ) {
    out.append(SearchAndReplaceWordsInText(words, line)+"\n");
    } finally {
    if(in!=null) in.close(); //may throw IOException
    return out.toString();
    * Replaces all occurrences in text of each key in words with it's value.
    * @returns String
    private static String SearchAndReplaceWordsInText(Map words, String text) {
    Iterator it = words.keySet().iterator();
    while( it.hasNext() ) {
    String key = (String)it.next();
    text = text.replaceAll("\\b"+key+"\\b", (String)words.get(key));
    return text;
    * @returns: s with the first letter capitalized
    String capitalize(String s)
    return s.substring(0,0).toUpperCase() + s.substring(1);
    }

    without what arguments?Without any arguments. If there are no arguments, there are no arguments of any kind. If you have a zoo with no animals in it, it's not meaningful to ask whether the animals which are not there are zebras or elephants.
    does it prompt me to give it a text file name?Apparently.
    when i run it this is all i get:
    usage: Translate wordmapfile textfile
    Press any key to continue...Right. And "wordmapfile" is almost certainly supposed to be a file that holds the word map, and "textfile" is almost certainly the file of text that it's going to translate.

  • URGETN HELP NEEDED! JAVA APPLET READING FILE

    Hi everyone
    I need to hand in this assignment today
    Im trying to read from a file and read it onto the screen, my code keeps showing up an error
    'missing method body, or declare abstract'
    This is coming up for the
    public statuc void main(String[] args);
    and the
    public void init();
    Here is my code:
    import java.io.*;
    import java.awt.*;
    import java.applet.*;
    public class Empty_3 extends Applet {
    TextArea ta = new TextArea();
    public static void main(String[] args);
    public void init();
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    try {
    InputStream in =
    getClass().getResourceAsStream("test1.txt");
    InputStreamReader isr =
    new InputStreamReader(in);
    BufferedReader br =
    new BufferedReader(isr);
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    String line;
    while ((line = br.readLine()) != null) {
    pw.println(line);
    ta.setText(sw.toString());
    } catch (IOException io) {
    ta.setText("Ooops");
    Can anyone help me please?
    Is this the best way of doing this? Once i read the file i want to perform a frequency analysis on the words so if there is a better method for this then please let me know!
    Thankyou
    Matt

    Whether it is urgent or not, does not interest us. It might be urgent for you but for nobody else.
    Writing all-capitals is considered shouting and rude.
    // Use code tags for source.

  • Java.nio read/write question

    Hello,
    I just started to learn the java.nio package so I decided to make a simple Echo server. I made a client which reads a line from the keyboard, sends it to the server and the server returns it. It all works except one little detail. Here's little code from the server:
                                 int n = client.read(buffer);
                                 if ( n > 0)
                                     buffer.flip();
                                     client.write(buffer);
                                     Charset charset = Charset.forName("ISO-8859-1");
                                     CharsetDecoder decoder = charset.newDecoder();
                                     charBuffer = decoder.decode(buffer);
                                     System.out.println(charBuffer.toString());
                                     buffer.clear();
                                  }So that works, I send the data and then I receive it back. But only for the client. I also wanted the server to print the line which is the reason for the charset and the decoder. The above code however prints only a blank line. Thus I tried this:
                                 int n = client.read(buffer);
                                 if ( n > 0)
                                     buffer.flip();
                                     Charset charset = Charset.forName("ISO-8859-1");
                                     CharsetDecoder decoder = charset.newDecoder();
                                     charBuffer = decoder.decode(buffer);
                                     System.out.println(charBuffer.toString());
                                     client.write(buffer);
                                     buffer.clear();
                                  }Or in other words I just moved the write() part downwards. So far so good, now the server was actually printing the lines that the client was sending but nothing was sent back to the client.
    The question is how to make both, the send back line and the print line on the server side to work as intended. Also a little explanation why the events described above are happening is going to be more than welcome :)
    Thanks in advance!

    Strike notice
    A number of the regular posters here are striking in protest at the poor
    management of these forums. Although it is our unpaid efforts which make the
    forums function, the Sun employees responsible for them seem to regard us as
    contemptible. We hope that this strike will enable them to see the value
    which we provide to Sun. Apologies to unsuspecting innocents caught up in
    the cross-fire.

  • Can't get java to read my file input

    I have a program that ask at prompt what the name of your input file will be... something for example like input.txt can be typed and a scanner puts that text "input.txt" into a string called maybe inputs.
    The problem I am having is I can not get the scanner to then look at the string and open the file with the same name in the folder and read it.
    I not sure if im putting the name correct in the new File so to make it look at "input.txt" and I keep getting Class FileNotFoundException
    any ideas?
    my code is below
    File f = new File(inputs);
    Scanner scan = new Scanner( f );
    String name = "";
    while(scan.hasNextLine()) // as long as there is another line to be read
         String text = scan.nextLine(); // read the first line
         Scanner scan2 = new Scanner(text); // set up a second scanner to process the String we just read in
         if(scan2.hasNext())
              name = scan2.next();
         else
              continue; // go to the next line
         System.out.println(name);
    }

    Java is likely looking for your file in a location other than where the file is. Do you know where your current user.dir is? Create a small program that does nothing but this:
    class Fubar
      public static void main(String[] args)
        System.out.println(System.getProperty("user.dir"));
    }Edited by: Encephalopathic on Mar 23, 2009 7:10 PM

  • Accessing OS/390 through Java and reading VSAM files

    I hope this is the apporiate forum for this question. I am fairly new to Java but am interested in learning about using Java to connect to a mainframe and read a VSAM file. So my questions are:
    1.) Where can I find information on this on this topic
    2.) Would this require database drivers, and if so, are there any open source drivers for reading VSAM
    Thanks for your help,
    John

    You can get an evaluation copy of WebSphere Information Integrator Classic Federation for z/OS v8.2. This will include JDBC clients for Windows and Unix platforms as well as a z/OS data server component that can access the VSAM data. .
    There are two ways to order an evaluation copy:
    Through the IBM zSeries account rep
    Via the Shop zSeries Web site

Maybe you are looking for