1: /* 2: * anchor.java 0.1 96/08/01 3: * 4: * Copyright (c) 1996 MARUYAMA Fujio All Rights Reserved. 5: * 6: * Permission to use, copy, modify, and distribute this software 7: * and its documentation for NON-COMMERCIAL purposes and without 8: * fee is hereby granted provided that this copyright notice 9: * appears in all copies. 10: * 11: * Mail : maruyama@wakhok.ac.jp 12: * 13: */ 14: 15: import java.io.*; 16: 17: class anchor { 18: 19: static final int BUFSIZE = 10000 ; // 大きさ10000バイトまで! 20: 21: public static void main(String argv[]){ 22: 23: byte bytebuf[] = new byte[BUFSIZE]; 24: try { 25: FileInputStream fin = new FileInputStream( argv[0] ); 26: int len=0 ; 27: int offset=0 ; 28: 29: while(( len= fin.read(bytebuf,offset,1000)) != -1 ){ 30: offset += len ; 31: System.out.println("offset="+ offset); 32: } 33: 34: } catch ( Exception e ){ 35: System.out.println("Exception : " + e ); 36: } 37: String str = new String(bytebuf,0); 38: 39: boolean append = false ; 40: String buff = ""; 41: int end = 0; 42: while( str.length() > 0 ){ 43: int start = str.indexOf('<'); 44: if ( start == -1 ) break ; 45: String text = str.substring(end, start); 46: text = text.trim(); 47: if ( text.length() != 0 ) { 48: if ( append ) buff += text ; 49: } 50: end = str.indexOf('>'); 51: if ( end == -1 ) break ; 52: String tag = str.substring(start, end+1); 53: if ( tag.startsWith("<A ") || tag.startsWith("<a ")){ 54: append = true ; 55: } else if ( tag.equalsIgnoreCase("</A>") ){ 56: append = false ; 57: System.out.println(buff); 58: buff = "" ; 59: } else { 60: if ( append ) buff += tag ; 61: } 62: str = str.substring(end+1); 63: end=0; 64: } 65: } 66: }
1: /* 2: * anchor2.java 0.1 96/08/01 3: * 4: * Copyright (c) 1996 MARUYAMA Fujio All Rights Reserved. 5: * 6: * Permission to use, copy, modify, and distribute this software 7: * and its documentation for NON-COMMERCIAL purposes and without 8: * fee is hereby granted provided that this copyright notice 9: * appears in all copies. 10: * 11: * Mail : maruyama@wakhok.ac.jp 12: * 13: */ 14: 15: import java.io.*; 16: 17: class anchor { 18: 19: static int size = 1000 ; 20: 21: public static void main(String argv[]){ 22: 23: byte bytebuf[] = new byte[size]; 24: int limit = (int)(size*8/10); 25: int oldsize = size; 26: 27: try { 28: FileInputStream fin = new FileInputStream( argv[0] ); 29: int len=0 ; 30: int offset=0 ; 31: 32: while(( len= fin.read(bytebuf,offset,100)) != -1 ){ 33: offset += len ; 34: System.out.println("offset="+ offset); 35: if ( offset > limit ){ 36: oldsize = size ; 37: size=size*2; 38: System.out.println("new size=" + size); 39: limit = (int)(size*8/10); 40: byte newbuf[] = new byte[size]; 41: System.arraycopy(bytebuf,0,newbuf,0,oldsize); 42: bytebuf = newbuf ; 43: } 44: } 45: } catch ( Exception e ){ 46: System.out.println("Exception : " + e ); 47: } 48: String str = new String(bytebuf,0); 49: 50: boolean append = false ; 51: String buff = ""; 52: int end = 0; 53: while( str.length() > 0 ){ 54: int start = str.indexOf('<'); 55: if ( start == -1 ) break ; 56: String text = str.substring(end, start); 57: text = text.trim(); 58: if ( text.length() != 0 ) { 59: if ( append ) buff += text ; 60: } 61: end = str.indexOf('>'); 62: if ( end == -1 ) break ; 63: String tag = str.substring(start, end+1); 64: if ( tag.startsWith("<A ") || tag.startsWith("<a ")){ 65: append = true ; 66: } else if ( tag.equalsIgnoreCase("</A>") ){ 67: append = false ; 68: System.out.println(buff); 69: buff = "" ; 70: } else { 71: if ( append ) buff += tag ; 72: } 73: str = str.substring(end+1); 74: end=0; 75: } 76: } 77: }
1: /* 2: * ImageCanvas.java 0.1 96/08/01 3: * 4: * Copyright (c) 1996 MARUYAMA Fujio All Rights Reserved. 5: * 6: * Permission to use, copy, modify, and distribute this software 7: * and its documentation for NON-COMMERCIAL purposes and without 8: * fee is hereby granted provided that this copyright notice 9: * appears in all copies. 10: * 11: * Mail : maruyama@wakhok.ac.jp 12: * 13: */ 14: 15: import java.awt.Frame; 16: import java.awt.Canvas; 17: import java.awt.Graphics; 18: import java.awt.Dimension; 19: import java.awt.Toolkit; 20: import java.awt.Event; 21: import sun.awt.image.* ; 22: 23: class ImageCanvas extends Canvas { 24: 25: public sun.awt.image.Image image=null; 26: public Dimension dim ; 27: public int width ; 28: public int height ; 29: 30: public Dimension preferredSize(){ 31: return minimumSize(); 32: } 33: 34: public synchronized Dimension minimumSize(){ 35: return dim; 36: } 37: 38: ImageCanvas(String src){ 39: image = getFileImage( src ); 40: dim = new Dimension(width,height); 41: repaint(); 42: this.resize(dim); 43: } 44: 45: public Image getFileImage(String filename){ 46: sun.awt.image.Image img=null; 47: try { 48: img = (sun.awt.image.Image)Toolkit.getDefaultToolkit().createImage( 49: new FileImageSource( filename )); 50: width = img.getWidth(); 51: height= img.getHeight(); 52: } catch (Exception e){ 53: System.err.println("getImage(URL) : " + e); 54: } 55: return img ; 56: } 57: 58: public void paint( Graphics g ) { 59: g.drawImage( image, 0, 0 , this); 60: } 61: 62: public boolean keyDown(Event e , int key){ 63: if ( key == 'q' ) System.exit(0); 64: return true ; 65: } 66: 67: public static void main(String argv[]){ 68: Frame f = new Frame("Draw Image"); 69: ImageCanvas si = new ImageCanvas(argv[0]); 70: f.add("Center",si); 71: f.resize(si.dim); 72: f.pack(); 73: f.show(); 74: } 75: 76: }