diff options
author | Robert Greig <rgreig@apache.org> | 2007-02-20 16:51:32 +0000 |
---|---|---|
committer | Robert Greig <rgreig@apache.org> | 2007-02-20 16:51:32 +0000 |
commit | 53dfa7e61494fc38de8b527a91dfdb6051260e2a (patch) | |
tree | 9c36100358f74974f5c5b544d8c09b5053aa6d6d /java/common | |
parent | 797b61fa56e3576e4a85780e7e8bdc20e6833d75 (diff) | |
download | qpid-python-53dfa7e61494fc38de8b527a91dfdb6051260e2a.tar.gz |
(Path submitted by Rupert Smith) Qpid-338. Custom SASL implementation for Java 1.4 retrotranslation of the Java client.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@509642 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common')
-rw-r--r-- | java/common/pom.xml | 74 | ||||
-rw-r--r-- | java/common/src/main/java/org/apache/qpid/util/FileUtils.java | 161 | ||||
-rw-r--r-- | java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java | 73 |
3 files changed, 272 insertions, 36 deletions
diff --git a/java/common/pom.xml b/java/common/pom.xml index c8168c34bb..5e94153346 100644 --- a/java/common/pom.xml +++ b/java/common/pom.xml @@ -15,7 +15,7 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - --> +--> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> @@ -67,35 +67,37 @@ <!-- Backports the module to Java 1.4. This is done during the packaging phase as a transformation of the Jar. --> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>retrotranslator-maven-plugin</artifactId> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>translate</goal> - </goals> - <configuration> - <destjar>${project.build.directory}/${project.build.finalName}-java1.4.jar</destjar> - <verify>${retrotranslator.verify}</verify> - <verifyClasspath> - <element>${retrotranslator.1.4-rt-path}</element> - <element>${retrotranslator.1.4-jce-path}</element> - <element>${retrotranslator.1.4-jsse-path}</element> - </verifyClasspath> - <includes> - <include> - <directory>${project.build.directory}</directory> - <pattern>${project.build.finalName}.jar</pattern> - </include> - </includes> - </configuration> - </execution> + <groupId>org.codehaus.mojo</groupId> + <artifactId>retrotranslator-maven-plugin</artifactId> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>translate</goal> + </goals> + <configuration> + <destjar>${project.build.directory}/${project.build.finalName}-java14.jar</destjar> + <verify>${retrotranslator.verify}</verify> + <verifyClasspath> + <element>${retrotranslator.1.4-rt-path}</element> + <element>${retrotranslator.1.4-jce-path}</element> + <element>${retrotranslator.1.4-jsse-path}</element> + <element>${retrotranslator.1.4-sasl-path}</element> + </verifyClasspath> + <failonwarning>false</failonwarning> + <includes> + <include> + <directory>${project.build.directory}</directory> + <pattern>${project.build.finalName}.jar</pattern> + </include> + </includes> + </configuration> + </execution> - </executions> + </executions> </plugin> - - <!-- This identifies the backported java 1.4 jar and attaches it as a jar (classified as java1.4) build artifact. --> + + <!-- This identifies the backported java 1.4 jar and attaches it as a jar (classified as java14) build artifact. --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> @@ -109,9 +111,9 @@ <configuration> <artifacts> <artifact> - <file>${project.build.directory}/${project.build.finalName}-java1.4.jar</file> + <file>${project.build.directory}/${project.build.finalName}-java14.jar</file> <type>jar</type> - <classifier>java1.4</classifier> + <classifier>java14</classifier> </artifact> </artifacts> </configuration> @@ -156,12 +158,12 @@ <scope>test</scope> </dependency> - <!-- This needs to be included at compile time, for the retrotranslator verification to find it. --> - <dependency> - <groupId>net.sf.retrotranslator</groupId> - <artifactId>retrotranslator-runtime</artifactId> - <scope>provided</scope> - </dependency> + <!-- This needs to be included at compile time, for the retrotranslator verification to find it. --> + <dependency> + <groupId>net.sf.retrotranslator</groupId> + <artifactId>retrotranslator-runtime</artifactId> + <scope>provided</scope> + </dependency> </dependencies> </project> diff --git a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java new file mode 100644 index 0000000000..ba79a6e8d4 --- /dev/null +++ b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java @@ -0,0 +1,161 @@ +/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.util;
+
+import java.io.*;
+
+import org.apache.log4j.Logger;
+
+/**
+ * FileUtils provides some simple helper methods for working with files. It follows the convention of wrapping all
+ * checked exceptions as runtimes, so code using these methods is free of try-catch blocks but does not expect to
+ * recover from errors.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Read a text file as a string.
+ * <tr><td> Open a file or default resource as an input stream.
+ * </table>
+ */
+public class FileUtils
+{
+ /**
+ * Reads a text file as a string.
+ *
+ * @param filename The name of the file.
+ *
+ * @return The contents of the file.
+ */
+ public static String readFileAsString(String filename)
+ {
+ BufferedInputStream is = null;
+
+ try
+ {
+ is = new BufferedInputStream(new FileInputStream(filename));
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ return readStreamAsString(is);
+ }
+
+ /**
+ * Reads a text file as a string.
+ *
+ * @param file The file.
+ *
+ * @return The contents of the file.
+ */
+ public static String readFileAsString(File file)
+ {
+ BufferedInputStream is = null;
+
+ try
+ {
+ is = new BufferedInputStream(new FileInputStream(file));
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ return readStreamAsString(is);
+ }
+
+ /**
+ * Reads the contents of a reader, one line at a time until the end of stream is encountered, and returns all
+ * together as a string.
+ *
+ * @param is The reader.
+ *
+ * @return The contents of the reader.
+ */
+ private static String readStreamAsString(BufferedInputStream is)
+ {
+ try
+ {
+ byte[] data = new byte[4096];
+
+ StringBuffer inBuffer = new StringBuffer();
+
+ String line;
+ int read;
+
+ while ((read = is.read(data)) != -1)
+ {
+ String s = new String(data, 0, read);
+ inBuffer.append(s);
+ }
+
+ return inBuffer.toString();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Either opens the specified filename as an input stream, or uses the default resource loaded using the
+ * specified class loader, if opening the file fails or no file name is specified.
+ *
+ * @param filename The name of the file to open.
+ * @param defaultResource The name of the default resource on the classpath if the file cannot be opened.
+ * @param cl The classloader to load the default resource with.
+ *
+ * @return An input stream for the file or resource, or null if one could not be opened.
+ */
+ public static InputStream openFileOrDefaultResource(String filename, String defaultResource, ClassLoader cl)
+ {
+ InputStream is = null;
+
+ // Flag to indicate whether the default resource should be used. By default this is true, so that the default
+ // is used when opening the file fails.
+ boolean useDefault = true;
+
+ // Try to open the file if one was specified.
+ if (filename != null)
+ {
+ try
+ {
+ is = new BufferedInputStream(new FileInputStream(new File(filename)));
+
+ // Clear the default flag because the file was succesfully opened.
+ useDefault = false;
+ }
+ catch (FileNotFoundException e)
+ {
+ // Ignore this exception, the default will be used instead.
+ }
+ }
+
+ // Load the default resource if a file was not specified, or if opening the file failed.
+ if (useDefault)
+ {
+ is = cl.getResourceAsStream(defaultResource);
+ }
+
+ return is;
+ }
+}
diff --git a/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java b/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java new file mode 100644 index 0000000000..faeb9d7167 --- /dev/null +++ b/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java @@ -0,0 +1,73 @@ +/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.util;
+
+/**
+ * Contains pretty printing convenienve methods for producing formatted logging output, mostly for debugging purposes.
+ *
+ * <p><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * </table>
+ */
+public class PrettyPrintingUtils
+{
+ /**
+ * Pretty prints an array of ints as a string.
+ *
+ * @param array The array to pretty print.
+ *
+ * @return The pretty printed string.
+ */
+ public static String printArray(int[] array)
+ {
+ String result = "[";
+ for (int i = 0; i < array.length; i++)
+ {
+ result += array[i];
+ result += (i < (array.length - 1)) ? ", " : "";
+ }
+
+ result += "]";
+
+ return result;
+ }
+
+ /**
+ * Pretty prints an array of strings as a string.
+ *
+ * @param array The array to pretty print.
+ *
+ * @return The pretty printed string.
+ */
+ public static String printArray(String[] array)
+ {
+ String result = "[";
+ for (int i = 0; i < array.length; i++)
+ {
+ result += array[i];
+ result += (i < (array.length - 1)) ? ", " : "";
+ }
+
+ result += "]";
+
+ return result;
+ }
+}
|