Ignore:
Timestamp:
Mar 27, 2011, 1:03:05 PM (13 years ago)
Author:
mlg
Message:

Adds a better Exception management
new Exception : FileAlreadyExistsException.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java

    r9879 r9893  
    1717import java.net.URLClassLoader;
    1818import java.security.MessageDigest;
     19import java.security.NoSuchAlgorithmException;
    1920import java.util.ArrayList;
    2021
     
    3233import org.jdom.output.XMLOutputter;
    3334
     35import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
     36
    3437/*
    3538 *  jiwigo-ws-api Piwigo webservice access Api
     
    123126     * @param filename the path of the file
    124127     * @return the checksum
     128     * @throws IOException
     129     * @throws NoSuchAlgorithmException
    125130     * @throws Exception
    126131     */
    127     public static String getMD5Checksum(String filename) throws Exception {
     132    public static String getMD5Checksum(String filename) throws NoSuchAlgorithmException, IOException {
    128133        byte[] b = createChecksum(filename);
    129134        String result = "";
     
    138143     * @param filename the path of the file
    139144     * @return the checksum as array byte
     145     * @throws NoSuchAlgorithmException
     146     * @throws IOException
    140147     * @throws Exception
    141148     */
    142     private static byte[] createChecksum(String filename) throws Exception {
     149    private static byte[] createChecksum(String filename) throws NoSuchAlgorithmException, IOException {
    143150        InputStream fis = new FileInputStream(filename);
    144151
     
    185192     * @return true if ok
    186193     */
    187     public static boolean checkOk(Document doc) {
     194    public static boolean checkOk(Document doc) throws FileAlreadyExistsException {
    188195        if (doc.getRootElement().getAttributeValue("stat").equals("ok")) {
    189196            return true;
     
    191198            LOG.error("Resultat : " + doc.getRootElement().getAttributeValue("stat") + "\nDocument retourné : \n"
    192199                    + Tools.documentToString(doc));
     200            if (doc.getRootElement().getChild("err").getAttributeValue("msg").equals("file already exists")) {
     201                throw new FileAlreadyExistsException("The file already exists on the server");
     202            }
    193203            return false;
    194204        }
Note: See TracChangeset for help on using the changeset viewer.