KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > mbean > TempFileCreatorService


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jmx.mbean;
23
24 import java.io.File JavaDoc;
25 import java.io.FileWriter JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.net.URL JavaDoc;
28
29 import org.jboss.logging.Logger;
30 import org.jboss.system.ServiceMBeanSupport;
31
32 //$Id: TempFileCreatorService.java 46080 2006-07-05 22:45:04Z asaldhana $
33

34 /**
35  * Service that creates temporary files on the server for testing purposes
36  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
37  * @since Jun 30, 2006
38  * @version $Revision: 46080 $
39  */

40 public class TempFileCreatorService extends ServiceMBeanSupport
41 implements TempFileCreatorServiceMBean
42 {
43    private static Logger log = Logger.getLogger(TempFileCreatorService.class);
44    
45    public TempFileCreatorService()
46    {
47    }
48    
49    public URL JavaDoc createTempFile(String JavaDoc filename, String JavaDoc data) throws IOException JavaDoc
50    {
51       log.debug("Passed filename="+filename);
52       File JavaDoc file = File.createTempFile(filename,".xml");
53       FileWriter JavaDoc fw = new FileWriter JavaDoc(file);
54       fw.write(data);
55       fw.close();
56       file.deleteOnExit();
57       URL JavaDoc url = file.toURL();
58       log.debug("Temp file created="+url.toExternalForm());
59       return url;
60    }
61 }
62
Popular Tags