Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class Main {
    public static String changeSizeThumbURL(String url, final int sizeWidthOfItem) {
        if ((url == null) || url.equals("")) {
            return url;
        }
        try {
            url = URLDecoder.decode(url, "UTF-8");
        } catch (final UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if (url.contains("/thumb_w/") && url.contains(",") && ((url.indexOf("/thumb_w/") + 5) < url.indexOf(","))) {
            final int size = (sizeWidthOfItem + 100) - (sizeWidthOfItem % 100);
            if ((size > 0) && (size < 1000) && ((size % 100) == 0)) {
                url = url.substring(0, url.indexOf("/thumb_w/")) + "/thumb_w/" + size
                        + url.substring(url.indexOf(","), url.length());
            }
        }
        return url;
    }
}