Re: input stream 101



blmblm@xxxxxxxxxxxxx wrote:
....
> Hm. Why do you want this interface BasicTidy? Maybe you shouldn't
> bother, but just define a class that provides only the functionality
> you want. If it's an interface, it won't be useful unless you
> have at least one class that implements it, and unless you think
> that eventually you'll want more than one class that implements it,
> what's the point of having a separately-defined interface? (Maybe
> someone else will have a better answer for that.)

Part of the justification for BasicTidy is for the sake of having an
interface and using it. BasicTidy does serve a practical purpose,
hopefully, in that down the line as I use more and more of the methods
in BasicTidy I won't have to look in Test16 to see the method
signatures but can just refer to BasicTidy which is much simpler.
Hopefully, BasicTidy is largely self-documenting. I should've been
doing documentation all along, of course. Mea culpa.

Possibly the code changed a bit since you last read it. Currently
BasicTidy implements Runnable and Test16 implements BasicTidy. I'm not
totally convinced that this is good, but it does mean that ControlTidy
doesn't have to deal with an object of type Test16, only the interface
of BasicTidy. This was one the chief reasons for ControlTidy's
existence, to create the simplest possible program for my needs. If
necesarry I can create an IntermediateTidy for Test16 to implement, but
I'm not sure what that would consist of.

>
> >(I'm not sure how to say that last one. There's the type (interface)
> >of an object, and then its type (instance of).)
>
> I'm not sure either, but I think you have the ideas straight anyway:
>
> For example, if class ControlTidy extends Tidy and implements Runnable
> (just an example, don't think this is how you should do things), when
> you say
>
> ControlTidy c = new ControlTidy();

Yes, this is a step I'm considering. For instance, there might a
GUItidy which sends url's to ControlTidy, or it might send a path to a
local file, too.

> you an object that's "really" a ControlTidy, but it could be used as
> a ControlTidy, a Tidy, or a Runnable. Or, of course, an Object.
>
> So c points to an object that's an instance of class ControlTidy,
> and yet all of the following should evaluate to true:
>
> c instanceof ControlTidy
>
> c instanceof Tidy
>
> c instanceof Runnable

Hmm, I never though of that, but that's interesting. For any object
foo, instanceof Object will evaluate to true. I'm not sure of the
application, but it's interesting. An object can have many "types".

>
> Anyway to get back to your question -- if you define an interface
> BasicTidy, then for an object to count as a BasicTidy, it has to
> be an instance of a class that implements the BasicTidy interface.
....

At one point ControlTidy instatiated an object which implemented
BasicTidy, then I took that out. Now, it's back. ControlTidy
instatiates:

BasicTidy basicTidy = new Test16();

Except that the name (reference?) for the object above is "foo" in the
actual code, I'm not sure why. I should change the name to basicTidy,
probably.


here's the full, current code:


[thufir@arrakis tidyXhtml]$ date
Tue Aug 2 12:03:05 IST 2005
[thufir@arrakis tidyXhtml]$ pwd
/home/thufir/java/src/atreides/tidyXhtml
[thufir@arrakis tidyXhtml]$ ll
total 24
-rw-rw-r-- 1 thufir thufir 284 Aug 2 00:36 BasicTidy.java
-rw-rw-r-- 1 thufir thufir 520 Aug 2 00:41 ControlTidy.java
-rw-rw-r-- 1 thufir thufir 1492 Aug 2 00:36 Test16.java
[thufir@arrakis tidyXhtml]$ cat BasicTidy.java -n
1 package atreides.tidyXhtml;
2
3 public interface BasicTidy extends Runnable{
4 public void setUrl(String url);
5 public void setOutFileName(String outFileName);
6 public void setErrOutFileName(String errOutFileName);
7 public void setXmlOut(boolean xmlOut);
8 public void run();
9 }//BasicTidy
[thufir@arrakis tidyXhtml]$ cat Test16.java -n
1 package atreides.tidyXhtml;
2
3 import java.io.IOException;
4 import java.net.URL;
5 import java.io.BufferedInputStream;
6 import java.io.FileOutputStream;
7 import java.io.PrintWriter;
8 import java.io.FileWriter;
9 import org.w3c.tidy.Tidy;
10
11
12 public class Test16 implements BasicTidy{
13
14 private String url;
15 private String outFileName;
16 private String errOutFileName;
17 private boolean xmlOut;
18
19 public Test16(){
20 this.url = "http://www.google.com/";;
21 this.outFileName = "out.txt";
22 this.errOutFileName = "err.txt";
23 this.xmlOut = true;
24 }//Test16
25
26 public void run() {
27 URL u;
28 BufferedInputStream in;
29 FileOutputStream out;
30 Tidy tidy = new Tidy();
31
32 tidy.setXmlOut(xmlOut);
33 try {
34 tidy.setErrout(new PrintWriter(new
FileWriter(errOutFileName), true));
35 u = new URL(url);
36 in = new
BufferedInputStream(u.openStream());
37 out = new
FileOutputStream(outFileName);
38 tidy.parse(in, out);
39 }//try
40 catch ( IOException e ) {
41 System.out.println( this.toString() +
e.toString() );
42 }//catch
43 }//run
44
45 public void setUrl (String url){
46 this.url = url;
47 }//setUrl
48
49 public void setOutFileName (String outFileName){
50 this.outFileName = outFileName;
51 }//setOutFileName
52
53 public void setErrOutFileName (String errOutFileName){
54 this.errOutFileName = errOutFileName;
55 }//setErrOutFileName
56
57 public void setXmlOut (boolean xmlOut) {
58 this.xmlOut = xmlOut;
59 }//setXmlOut
60
61 public static void main( String[] args ) {
62 }//main
63 }//Test16
[thufir@arrakis tidyXhtml]$ cat ControlTidy.java -n
1 package atreides.tidyXhtml;
2
3 public class ControlTidy{
4
5 public static void main (String[] args) {
6 String yahooUrl =
"http://www.yahoo.com/";;
7 String googleUrl =
"http://www.google.com/";;
8 String out = "out.txt";
9 String err = "err.txt";
10 boolean xml = true;
11 boolean xhtml = false;
12 BasicTidy foo = new Test16();
13
14 foo.setUrl (yahooUrl);
15 foo.setOutFileName (out);
16 foo.setErrOutFileName (err);
17 foo.setXmlOut(xml);
18
19 Thread fooThread = new Thread(foo);
20 fooThread.start();
21 }//main
22 }//ControlTidy
[thufir@arrakis tidyXhtml]$



-Thufir

.



Relevant Pages

  • Re: input stream 101
    ... >I do want to create my own interface, BasicTidy ... >I do want ControlTidy to call methods on an object which is of type ... Why do you want this interface BasicTidy? ... if class ControlTidy extends Tidy and implements Runnable ...
    (comp.lang.java.help)
  • Re: input stream 101
    ... Why do you want this interface BasicTidy? ... >BasicTidy implements Runnable and Test16 implements BasicTidy. ... if class ControlTidy extends Tidy and implements Runnable ...
    (comp.lang.java.help)
  • Re: input stream 101
    ... If you want something with a GUI for those ... I do want to create my own interface, BasicTidy ... I do want ControlTidy to call methods on an object which is of type ...
    (comp.lang.java.help)
  • Re: input stream 101
    ... the reason for having a separate interface definition is to have ... except that Test16 also has a constructor. ... Why not just have a class BasicTidy? ... All the HTML files are the same pattern. ...
    (comp.lang.java.help)
  • Re: input stream 101
    ... I have a BasicTidy interface to throw into the mix. ... package atreides.tidyXhtml; ... 12 public class Test16 implements Runnable, ... public class ControlTidy{ ...
    (comp.lang.java.help)