From 914ac6cb326a5ad378adce50e4761cee13c72e4f Mon Sep 17 00:00:00 2001
From: bancika
Date: Sun, 2 Jan 2011 12:22:02 +0000
Subject: [PATCH] code format
---
.../diyfever/httpproxy/ClientHttpRequest.java | 68 +++++++++++--------
.../com/diyfever/httpproxy/IFlatProxy.java | 6 +-
.../diyfever/httpproxy/JavaStringSource.java | 4 +-
.../com/diyfever/httpproxy/PhpFlatProxy.java | 6 +-
.../com/diyfever/httpproxy/ProxyFactory.java | 51 ++++++--------
.../com/diyfever/httpproxy/MockFlatProxy.java | 9 +--
.../diyfever/httpproxy/ProxyFactoryTest.java | 6 +-
7 files changed, 70 insertions(+), 80 deletions(-)
diff --git a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/ClientHttpRequest.java b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/ClientHttpRequest.java
index ff0f618..655c07a 100644
--- a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/ClientHttpRequest.java
+++ b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/ClientHttpRequest.java
@@ -17,8 +17,8 @@
* Title: Client HTTP Request class
*
*
- * Description: this class helps to send POST HTTP requests with various form data, including files.
- * Cookies can be added to be included in the request.
+ * Description: this class helps to send POST HTTP requests with various form
+ * data, including files. Cookies can be added to be included in the request.
*
*
* @author Vlad Patryshev
@@ -70,7 +70,8 @@ private void boundary() throws IOException {
}
/**
- * Creates a new multipart POST HTTP request on a freshly opened URLConnection
+ * Creates a new multipart POST HTTP request on a freshly opened
+ * URLConnection
*
* @param connection
* an already open URL connection
@@ -150,8 +151,8 @@ public void setCookies(Map cookies) throws IOException {
* adds cookies to the request
*
* @param cookies
- * array of cookie names and values (cookies[2*i] is a name, cookies[2*i + 1] is a
- * value)
+ * array of cookie names and values (cookies[2*i] is a name,
+ * cookies[2*i + 1] is a value)
* @throws IOException
*/
public void setCookies(String[] cookies) throws IOException {
@@ -243,13 +244,15 @@ public void setParameter(String name, File file) throws IOException {
}
/**
- * adds a parameter to the request; if the parameter is a File, the file is uploaded, otherwise
- * the string value of the parameter is passed in the request
+ * adds a parameter to the request; if the parameter is a File, the file is
+ * uploaded, otherwise the string value of the parameter is passed in the
+ * request
*
* @param name
* parameter name
* @param object
- * parameter value, a File or anything else that can be stringified
+ * parameter value, a File or anything else that can be
+ * stringified
* @throws IOException
*/
public void setParameter(String name, Object object) throws IOException {
@@ -264,8 +267,9 @@ public void setParameter(String name, Object object) throws IOException {
* adds parameters to the request
*
* @param parameters
- * "name-to-value" map of parameters; if a value is a file, the file is uploaded,
- * otherwise it is stringified and sent in the request
+ * "name-to-value" map of parameters; if a value is a file, the
+ * file is uploaded, otherwise it is stringified and sent in the
+ * request
* @throws IOException
*/
public void setParameters(Map parameters) throws IOException {
@@ -281,9 +285,10 @@ public void setParameters(Map parameters) throws IOException {
* adds parameters to the request
*
* @param parameters
- * array of parameter names and values (parameters[2*i] is a name, parameters[2*i +
- * 1] is a value); if a value is a file, the file is uploaded, otherwise it is
- * stringified and sent in the request
+ * array of parameter names and values (parameters[2*i] is a
+ * name, parameters[2*i + 1] is a value); if a value is a file,
+ * the file is uploaded, otherwise it is stringified and sent in
+ * the request
* @throws IOException
*/
public void setParameters(Object[] parameters) throws IOException {
@@ -295,7 +300,8 @@ public void setParameters(Object[] parameters) throws IOException {
}
/**
- * posts the requests to the server, with all the cookies and parameters that were added
+ * posts the requests to the server, with all the cookies and parameters
+ * that were added
*
* @return input stream with the server response
* @throws IOException
@@ -308,8 +314,9 @@ public InputStream post() throws IOException {
}
/**
- * posts the requests to the server, with all the cookies and parameters that were added before
- * (if any), and with parameters that are passed in the argument
+ * posts the requests to the server, with all the cookies and parameters
+ * that were added before (if any), and with parameters that are passed in
+ * the argument
*
* @param parameters
* request parameters
@@ -323,8 +330,9 @@ public InputStream post(Map parameters) throws IOException {
}
/**
- * posts the requests to the server, with all the cookies and parameters that were added before
- * (if any), and with parameters that are passed in the argument
+ * posts the requests to the server, with all the cookies and parameters
+ * that were added before (if any), and with parameters that are passed in
+ * the argument
*
* @param parameters
* request parameters
@@ -338,8 +346,9 @@ public InputStream post(Object[] parameters) throws IOException {
}
/**
- * posts the requests to the server, with all the cookies and parameters that were added before
- * (if any), and with cookies and parameters that are passed in the arguments
+ * posts the requests to the server, with all the cookies and parameters
+ * that were added before (if any), and with cookies and parameters that are
+ * passed in the arguments
*
* @param cookies
* request cookies
@@ -357,8 +366,9 @@ public InputStream post(Map cookies, Map parameters) throws IOException {
}
/**
- * posts the requests to the server, with all the cookies and parameters that were added before
- * (if any), and with cookies and parameters that are passed in the arguments
+ * posts the requests to the server, with all the cookies and parameters
+ * that were added before (if any), and with cookies and parameters that are
+ * passed in the arguments
*
* @param cookies
* request cookies
@@ -467,7 +477,8 @@ public InputStream post(String name1, Object value1, String name2, Object value2
}
/**
- * posts a new request to specified URL, with parameters that are passed in the argument
+ * posts a new request to specified URL, with parameters that are passed in
+ * the argument
*
* @param parameters
* request parameters
@@ -480,7 +491,8 @@ public static InputStream post(URL url, Map parameters) throws IOException {
}
/**
- * posts a new request to specified URL, with parameters that are passed in the argument
+ * posts a new request to specified URL, with parameters that are passed in
+ * the argument
*
* @param parameters
* request parameters
@@ -493,8 +505,8 @@ public static InputStream post(URL url, Object[] parameters) throws IOException
}
/**
- * posts a new request to specified URL, with cookies and parameters that are passed in the
- * argument
+ * posts a new request to specified URL, with cookies and parameters that
+ * are passed in the argument
*
* @param cookies
* request cookies
@@ -510,8 +522,8 @@ public static InputStream post(URL url, Map cookies, Map parameters) throws IOEx
}
/**
- * posts a new request to specified URL, with cookies and parameters that are passed in the
- * argument
+ * posts a new request to specified URL, with cookies and parameters that
+ * are passed in the argument
*
* @param cookies
* request cookies
diff --git a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/IFlatProxy.java b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/IFlatProxy.java
index 0a972ea..0621132 100644
--- a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/IFlatProxy.java
+++ b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/IFlatProxy.java
@@ -24,8 +24,7 @@ public interface IFlatProxy {
* parameters.
* @return streamed server response
*/
- public InputStream invoke(String url, String methodName,
- Map params);
+ public InputStream invoke(String url, String methodName, Map params);
/**
* Invokes the specified method on the specified url and returns
@@ -41,6 +40,5 @@ public InputStream invoke(String url, String methodName,
* parameters.
* @return deserialized server response
*/
- public Object invokeAndDeserialize(String url, String methodName,
- Map params);
+ public Object invokeAndDeserialize(String url, String methodName, Map params);
}
diff --git a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/JavaStringSource.java b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/JavaStringSource.java
index 075bee5..650214b 100644
--- a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/JavaStringSource.java
+++ b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/JavaStringSource.java
@@ -9,8 +9,8 @@ public class JavaStringSource extends SimpleJavaFileObject {
final String code;
JavaStringSource(String name, String code) {
- super(URI.create("string:///" + name.replace('.', '/')
- + Kind.SOURCE.extension), Kind.SOURCE);
+ super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension),
+ Kind.SOURCE);
this.code = code;
}
diff --git a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/PhpFlatProxy.java b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/PhpFlatProxy.java
index 5cc2716..3ee0b49 100644
--- a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/PhpFlatProxy.java
+++ b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/PhpFlatProxy.java
@@ -29,8 +29,7 @@ public class PhpFlatProxy implements IFlatProxy {
private static final Logger LOG = Logger.getLogger(PhpFlatProxy.class);
@Override
- public InputStream invoke(String url, String methodName,
- Map params) {
+ public InputStream invoke(String url, String methodName, Map params) {
InputStream serverInput;
try {
// Flatten params map into an array
@@ -55,8 +54,7 @@ public InputStream invoke(String url, String methodName,
}
@Override
- public Object invokeAndDeserialize(String url, String methodName,
- Map params) {
+ public Object invokeAndDeserialize(String url, String methodName, Map params) {
InputStream stream = invoke(url, methodName, params);
if (stream == null) {
return null;
diff --git a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/ProxyFactory.java b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/ProxyFactory.java
index 296c754..8980ec1 100644
--- a/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/ProxyFactory.java
+++ b/ java-http-proxy --username bancika@gmail.com/HttpProxy/src/com/diyfever/httpproxy/ProxyFactory.java
@@ -41,8 +41,7 @@ public ProxyFactory(IFlatProxy flatProxy) {
super();
this.flatProxy = flatProxy;
- this.fileClassLoader = new FileClassLoader(ToolProvider
- .getSystemToolClassLoader());
+ this.fileClassLoader = new FileClassLoader(ToolProvider.getSystemToolClassLoader());
this.compiler = ToolProvider.getSystemJavaCompiler();
}
@@ -62,32 +61,24 @@ public ProxyFactory(IFlatProxy flatProxy) {
@SuppressWarnings("unchecked")
public T createProxy(Class extends T> clazz, String url) {
if (!clazz.isInterface()) {
- LOG
- .error("Specified class is not an interface: "
- + clazz.getName());
+ LOG.error("Specified class is not an interface: " + clazz.getName());
return null;
}
String interfaceName = clazz.getName();
- String newClassName = interfaceName.substring(interfaceName
- .lastIndexOf(".") + 1)
- + "Impl";
+ String newClassName = interfaceName.substring(interfaceName.lastIndexOf(".") + 1) + "Impl";
try {
LOG.info("Creating temp class code");
StringWriter writer = new StringWriter();
PrintWriter out = new PrintWriter(writer);
- out.println("public class " + newClassName + " implements "
- + interfaceName + " {\n");
- out
- .println(" private " + IFlatProxy.class.getName()
- + " proxy;\n");
+ out.println("public class " + newClassName + " implements " + interfaceName + " {\n");
+ out.println(" private " + IFlatProxy.class.getName() + " proxy;\n");
// Generate a constructor
- out.println(" public " + newClassName + "("
- + IFlatProxy.class.getName()
+ out.println(" public " + newClassName + "(" + IFlatProxy.class.getName()
+ " proxy) { this.proxy = proxy; }\n");
for (Method method : clazz.getDeclaredMethods()) {
- out.print(" public " + method.getReturnType().getName() + " "
- + method.getName() + "(");
+ out.print(" public " + method.getReturnType().getName() + " " + method.getName()
+ + "(");
for (int i = 0; i < method.getParameterTypes().length; i++) {
if (i > 0) {
out.print(", ");
@@ -102,8 +93,7 @@ public T createProxy(Class extends T> clazz, String url) {
.println(" java.util.Map params = new java.util.HashMap();");
for (int i = 0; i < method.getParameterTypes().length; i++) {
String paramName = extractParameterName(method, i);
- out.println(" params.put(\"" + paramName + "\", "
- + paramName + ");");
+ out.println(" params.put(\"" + paramName + "\", " + paramName + ");");
}
// Call the proxy
@@ -113,9 +103,9 @@ public T createProxy(Class extends T> clazz, String url) {
} else {
factoryMethodName = "invokeAndDeserialize";
}
- out.println(" return (" + method.getReturnType().getName()
- + ") proxy." + factoryMethodName + "(\"" + url
- + "\", \"" + method.getName() + "\", params);");
+ out.println(" return (" + method.getReturnType().getName() + ") proxy."
+ + factoryMethodName + "(\"" + url + "\", \"" + method.getName()
+ + "\", params);");
out.println(" }\n");
}
out.print("}\n");
@@ -126,17 +116,15 @@ public T createProxy(Class extends T> clazz, String url) {
LOG.info("Compiling temp class");
DiagnosticCollector diagnostics = new DiagnosticCollector();
- Iterable extends JavaFileObject> compilationUnits = Arrays
- .asList(file);
+ Iterable extends JavaFileObject> compilationUnits = Arrays.asList(file);
// Create temp directory if it doesn't exist.
File tempDir = new File("temp/");
if (!tempDir.exists()) {
tempDir.mkdir();
}
- JavaCompiler.CompilationTask task = compiler.getTask(null, null,
- diagnostics, Arrays.asList(new String[] { "-d", "temp" }),
- null, compilationUnits);
+ JavaCompiler.CompilationTask task = compiler.getTask(null, null, diagnostics, Arrays
+ .asList(new String[] { "-d", "temp" }), null, compilationUnits);
boolean success = task.call();
if (success) {
LOG.info("Successfully compiled code");
@@ -149,8 +137,8 @@ public T createProxy(Class extends T> clazz, String url) {
}
T instance = (T) fileClassLoader.createClass(
- new File("temp/" + newClassName + ".class"))
- .getConstructors()[0].newInstance(flatProxy);
+ new File("temp/" + newClassName + ".class")).getConstructors()[0]
+ .newInstance(flatProxy);
LOG.info("Successfully instantiated proxy");
return instance;
} catch (Exception e) {
@@ -167,9 +155,8 @@ private String extractParameterName(Method method, int parameterIndex) {
return ((ParamName) annotation).value();
}
}
- LOG.warn("@" + ParamName.class.getSimpleName()
- + " annotation not present for method " + method.getName()
- + ", at index " + parameterIndex);
+ LOG.warn("@" + ParamName.class.getSimpleName() + " annotation not present for method "
+ + method.getName() + ", at index " + parameterIndex);
return "param" + parameterIndex;
}
}
\ No newline at end of file
diff --git a/ java-http-proxy --username bancika@gmail.com/HttpProxy/test/com/diyfever/httpproxy/MockFlatProxy.java b/ java-http-proxy --username bancika@gmail.com/HttpProxy/test/com/diyfever/httpproxy/MockFlatProxy.java
index a747b3e..8cfd3c1 100644
--- a/ java-http-proxy --username bancika@gmail.com/HttpProxy/test/com/diyfever/httpproxy/MockFlatProxy.java
+++ b/ java-http-proxy --username bancika@gmail.com/HttpProxy/test/com/diyfever/httpproxy/MockFlatProxy.java
@@ -11,20 +11,17 @@
public class MockFlatProxy implements IFlatProxy {
@Override
- public InputStream invoke(String url, String methodName,
- Map params) {
+ public InputStream invoke(String url, String methodName, Map params) {
// InputStream stream = new ByteArrayInputStream(("{\"string\":\""
// + params.get("name").toString() + "\"}").getBytes());
XStream xstream = new XStream(new JettisonMappedXmlDriver());
xstream.setMode(XStream.NO_REFERENCES);
- InputStream stream = new ByteArrayInputStream(xstream.toXML(
- params.get("name")).getBytes());
+ InputStream stream = new ByteArrayInputStream(xstream.toXML(params.get("name")).getBytes());
return stream;
}
@Override
- public Object invokeAndDeserialize(String url, String methodName,
- Map params) {
+ public Object invokeAndDeserialize(String url, String methodName, Map params) {
return params.get("name");
}
}
diff --git a/ java-http-proxy --username bancika@gmail.com/HttpProxy/test/com/diyfever/httpproxy/ProxyFactoryTest.java b/ java-http-proxy --username bancika@gmail.com/HttpProxy/test/com/diyfever/httpproxy/ProxyFactoryTest.java
index f6a8d00..8e08fb6 100644
--- a/ java-http-proxy --username bancika@gmail.com/HttpProxy/test/com/diyfever/httpproxy/ProxyFactoryTest.java
+++ b/ java-http-proxy --username bancika@gmail.com/HttpProxy/test/com/diyfever/httpproxy/ProxyFactoryTest.java
@@ -25,16 +25,14 @@ public void setUp() throws Exception {
@Test
public void testCreateProxyString() {
- ITestProxy proxy = factory.createProxy(ITestProxy.class,
- "doesn't matter");
+ ITestProxy proxy = factory.createProxy(ITestProxy.class, "doesn't matter");
String name = "bancika";
assertEquals(name, proxy.test(name));
}
@Test
public void testCreateProxyStream() throws IOException {
- ITestProxy proxy = factory.createProxy(ITestProxy.class,
- "doesn't matter");
+ ITestProxy proxy = factory.createProxy(ITestProxy.class, "doesn't matter");
String name = "bancika";
InputStream stream = proxy.testStream(name);
byte[] buff = new byte[256];