View Javadoc

1   /*
2    * @(#) $Id: JISDataSource.java,v 1.1.2.1 2005/01/18 07:20:59 otsuka Exp $
3    * $Revision: 1.1.2.1 $
4    * Copyright (c) 2000 Shin Kinoshita All Rights Reserved.
5    */
6   package com.ozacc.mail.fetch.impl.sk_jp;
7   
8   import java.io.ByteArrayInputStream;
9   import java.io.IOException;
10  import java.io.InputStream;
11  import java.io.OutputStream;
12  import java.io.UnsupportedEncodingException;
13  
14  import javax.activation.DataSource;
15  
16  import com.ozacc.mail.fetch.impl.sk_jp.io.CharCodeConverter;
17  import com.ozacc.mail.fetch.impl.sk_jp.io.UnicodeCorrector;
18  
19  /***
20   * テキストの本文を送信するための DataSource です。
21   */
22  public class JISDataSource implements DataSource {
23  
24  	private byte[] data;
25  
26  	public JISDataSource(String s) {
27  		try {
28  			data = CharCodeConverter.sjisToJis(UnicodeCorrector.getInstance("Windows-31J").correct(
29  					s).getBytes("Windows-31J"));
30  		} catch (UnsupportedEncodingException e) {
31  			throw new RuntimeException("CANT HAPPEN");
32  		}
33  	}
34  
35  	public String getContentType() {
36  		return "text/plain; charset=ISO-2022-JP";
37  	}
38  
39  	public InputStream getInputStream() throws IOException {
40  		if (data == null)
41  			throw new IOException("no data");
42  		return new ByteArrayInputStream(data);
43  	}
44  
45  	public OutputStream getOutputStream() throws IOException {
46  		throw new IOException("cannot do this");
47  	}
48  
49  	public String getName() {
50  		return "dummy";
51  	}
52  }