View Javadoc

1   package org.codehaus.mojo.jboss;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file 
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing, 
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
17   * KIND, either express or implied.  See the License for the 
18   * specific language governing permissions and limitations 
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.FileWriter;
24  import java.io.IOException;
25  import java.io.InputStream;
26  import java.io.PrintWriter;
27  
28  /**
29   * Provides generic methods supporting plugin functionality
30   * 
31   * @author pgier
32   */
33  public class JBossServerUtil
34  {
35      
36      /**
37       * Dump output coming from the stream
38       * 
39       * @param input The input stream to dump
40       */
41      public static void dump( final InputStream input )
42      {
43          final int streamBufferSize = 1000;
44          new Thread( new Runnable()
45          {
46              public void run()
47              {
48                  try
49                  {
50                      byte[] b = new byte[streamBufferSize];
51                      while ( ( input.read( b ) ) != -1 )
52                      {
53                      }
54                  }
55                  catch ( IOException e )
56                  {
57                      e.printStackTrace();
58                  }
59              }
60          } ).start();
61      }
62  
63      /**
64       * Create a policyFile that will allow the plugin to execute remote RMI code.
65       * 
66       * @param policyFile
67       * @throws IOException
68       */
69      public static void writeSecurityPolicy( File policyFile )
70          throws IOException
71      {
72          PrintWriter writer = new PrintWriter( new FileWriter( policyFile ) );
73          writer.println( "grant {" );
74          writer.println( "    permission java.security.AllPermission;" );
75          writer.println( "};" );
76          writer.close();
77      }
78  
79  }