Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleTextFileReader
linenumberstrue
collapsetrue
public class TextFileReader implements  InputChannel
{
    private String  itsFileName;
    private BufferedReader itsFileReader;
    
    public  TextFileReader()
    {
    }
    
    public  void    openForWriting( String fname )
    {
        itsFileName = fname;
        
        try
        {
            itsFileReader = new BufferedReader(new FileReader(fname));
        } catch (IOException ex)
        {
            Logger.getLogger(TextFileWriter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }    
    @Override
    public  String    read()
    {
        StringBuilder sb = new StringBuilder();
        String line;
        try
        {
            while( (line = itsFileReader.readLine()) != null )
                sb.append(line );
        } catch (IOException ex)
        {
            Logger.getLogger(TextFileReader.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally
        {
            close();
        }
        return sb.toString();
    }   
    
    @Override
    public  void    close()
    {
        try
        {
            itsFileReader.close();
        } catch (IOException ex)
        {
            Logger.getLogger(TextFileReader.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}


Now add the following lines of code to MainUnit to test your code

Code Block
languagejava
titleMainUnit - reading from a file
linenumberstrue
collapsetrue
// Read the files back in
System.out.println( "===========================================" );
TextFileReader tfr = new TextFileReader();
tfr.openForWriting("c:\\tmp\\account.json");
String jsonStream = tfr.read();
System.out.println( jsonStream );

tfr.openForWriting("c:\\tmp\\account.xml");
String xmlStream = tfr.read();
System.out.println( xmlStream );

tfr.openForWriting("c:\\tmp\\customer.json");
jsonStream = tfr.read();
System.out.println( jsonStream );


Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@2007c5
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "kb-troubleshooting-article" and type = "page" and space = "DJFE"
labelskb-troubleshooting-article

...