Changeset 4061 for branches


Ignore:
Timestamp:
Dec 7, 2010, 11:07:13 AM (13 years ago)
Author:
Gregory Vincic
Message:

Cleaning up source code

Location:
branches/gregorys
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/gregorys/build.xml

    r3754 r4061  
    9191           classpathref="classpath"
    9292           debug="true"
    93            deprecation="true">
     93           deprecation="true"
     94       includeantruntime="false">
    9495      <compilerarg value="-Xlint:unchecked" />
    9596    </javac>
  • branches/gregorys/src/pse/shared/Client.java

    r3758 r4061  
    11/*
    2   Copyright (C) 2010 Gregory Vincic
    3   License: http://www.gnu.org/licenses/gpl-3.0.txt
     2    Copyright (C) 2010 Gregory Vincic
     3    License: http://www.gnu.org/licenses/gpl-3.0.txt
    44*/
    55package pse.shared;
    66
     7import java.io.*;
    78import org.apache.commons.httpclient.*;
    89import org.apache.commons.httpclient.methods.*;
    910import org.apache.commons.httpclient.methods.multipart.*;
    10 import java.io.*;
    1111
    1212/**
    13  Wrapper for apaches HttpClient.
     13    Wrapper for apaches HttpClient.
    1414*/
    1515public class Client
    1616{
    17 
    18  /**
    19   Sends a multipart POST request to the given url with the given parts as parameters.
    20   @param url to send the request to
    21   @param parts parameters to send
    22  */
    23  public InputStream post(String url, Parts parts) throws IOException
    24  {
    25   PostMethod postMethod;
    26     HttpClient httpClient;
    27   MultipartRequestEntity entity;
    28   Integer statusCode;
    29   InputStream in;
    30  
    31   httpClient = new HttpClient();
    32   postMethod = new PostMethod(url);
    33   entity = new MultipartRequestEntity(parts.toArray(), postMethod.getParams());
    34 
    35   postMethod.setRequestEntity(entity);
    36   statusCode = httpClient.executeMethod(postMethod);
    37   return postMethod.getResponseBodyAsStream();
    38  }
     17   
     18    /**
     19        Sends a multipart POST request to the given url with the given parts as parameters.
     20        @param url to send the request to
     21        @param parts parameters to send
     22    */
     23    public InputStream post(String url, Parts parts) throws IOException
     24    {
     25        PostMethod postMethod;
     26        HttpClient httpClient;
     27        MultipartRequestEntity entity;
     28        Integer statusCode;
     29        InputStream in;
     30         
     31        httpClient = new HttpClient();
     32        postMethod = new PostMethod(url);
     33        entity = new MultipartRequestEntity(parts.toArray(), postMethod.getParams());
     34       
     35        postMethod.setRequestEntity(entity);
     36        statusCode = httpClient.executeMethod(postMethod);
     37        return postMethod.getResponseBodyAsStream();
     38    }
    3939}
  • branches/gregorys/src/pse/shared/Parts.java

    r3758 r4061  
    11/*
    2   Copyright (C) 2010 Gregory Vincic
    3   License: http://www.gnu.org/licenses/gpl-3.0.txt
     2    Copyright (C) 2010 Gregory Vincic
     3    License: http://www.gnu.org/licenses/gpl-3.0.txt
    44*/
    55package pse.shared;
     
    77import java.io.File;
    88import java.io.IOException;
     9import java.net.URI;
     10import java.util.ArrayList;
    911import java.util.List;
    10 import java.util.ArrayList;
    11 import java.net.URI;
     12import org.apache.commons.httpclient.*;
    1213import org.apache.commons.httpclient.methods.multipart.*;
    13 import org.apache.commons.httpclient.*;
    1414
    1515/**
    16  Parts are parameters send with the httpclient.
     16    Parts are parameters send with the httpclient.
    1717*/
    1818public class Parts extends ArrayList<Part>
    1919{
    20  public Parts(int size)
    21  {
    22   super(size);
    23  }
    24 
    25 
    26  public void add(String name, String value)
    27  {
    28   Part part;
    29   part = new StringPart(name, value);
    30   this.add(part);
    31  }
    32 
    33 
    34  public void add(String name, List<String> value)
    35  {
    36   Part part;
    37   for(String v : value)
    38   {
    39    part = new StringPart(name, v);
    40    this.add(part);
    41   }
    42  }
    43 
    44 
    45  public void add(String name, URI uri) throws IOException
    46  {
    47   File file;
    48   FilePartSource source;
    49   FilePart part;
    50 
    51   file = new File(uri);
    52   source = new FilePartSource(file);
    53   part = new FilePart(name, source);
    54   this.add(part);
    55  }
    56 
    57 
    58  public Part[] toArray()
    59  {
    60   Part[] list;
    61   list = new Part[this.size()];
    62   for(int i = 0; i < this.size(); i++)
    63   {
    64    list[i] = this.get(i);
    65   }
    66   return list;
    67  }
     20    public Parts(int size)
     21    {
     22        super(size);
     23    }
     24   
     25    public void add(String name, String value)
     26    {
     27        Part part;
     28        part = new StringPart(name, value);
     29        this.add(part);
     30    }
     31   
     32    public void add(String name, List<String> value)
     33    {
     34        Part part;
     35        for(String v : value)
     36        {
     37            part = new StringPart(name, v);
     38            this.add(part);
     39        }
     40    }
     41   
     42    public void add(String name, URI uri) throws IOException
     43    {
     44        File file;
     45        FilePartSource source;
     46        FilePart part;
     47       
     48        file = new File(uri);
     49        source = new FilePartSource(file);
     50        part = new FilePart(name, source);
     51        this.add(part);
     52    }
     53   
     54    public Part[] toArray()
     55    {
     56        Part[] list;
     57        list = new Part[this.size()];
     58        for(int i = 0; i < this.size(); i++)
     59        {
     60            list[i] = this.get(i);
     61        }
     62        return list;
     63    }
    6864}
Note: See TracChangeset for help on using the changeset viewer.