Changeset 7714


Ignore:
Timestamp:
May 21, 2019, 1:37:09 PM (2 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #2180: Replace "UTF-8" with StandardCharsets?.UTF_8

Location:
trunk/src
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/fileupload/FileUpload.java

    r7390 r7714  
    3737import java.net.SocketTimeoutException;
    3838import java.nio.charset.Charset;
     39import java.nio.charset.StandardCharsets;
    3940
    4041import javax.servlet.ServletRequest;
     
    166167    catch (Exception ex)
    167168    {
    168       this.charset = Charset.forName("UTF-8");
     169      this.charset = StandardCharsets.UTF_8;
    169170    }
    170171   
  • trunk/src/clients/web/net/sf/basedb/clients/web/plugins/SimpleExport.java

    r7651 r7714  
    7777import java.io.OutputStreamWriter;
    7878import java.io.Writer;
     79import java.nio.charset.StandardCharsets;
    7980import java.util.ArrayList;
    8081import java.util.Arrays;
     
    583584    else
    584585    {
    585       Writer exportStream = new OutputStreamWriter(out, "UTF-8");
     586      Writer exportStream = new OutputStreamWriter(out, StandardCharsets.UTF_8);
    586587      // Create export template for outputting the data
    587588      template = "xml".equals(format) ?
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/Download.java

    r7540 r7714  
    4949import java.io.IOException;
    5050import java.net.URLDecoder;
    51 
     51import java.nio.charset.StandardCharsets;
    5252import java.util.regex.Pattern;
    5353import java.util.regex.Matcher;
     
    101101    String servletPath = request.getServletPath();
    102102    String pathInfo = usePathInfo ? request.getPathInfo() :
    103       URLDecoder.decode(request.getRequestURI(), "UTF-8").replace(contextPath+servletPath, "");
     103      URLDecoder.decode(request.getRequestURI(), StandardCharsets.UTF_8).replace(contextPath+servletPath, "");
    104104    String range = request.getHeader("Range");
    105105    String ifRange = request.getHeader("If-Range");
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/RssNewsFeed.java

    r7394 r7714  
    2323import java.io.IOException;
    2424import java.nio.charset.Charset;
     25import java.nio.charset.StandardCharsets;
    2526import java.text.SimpleDateFormat;
    2627import java.util.ArrayList;
     
    110111    contextPath = context.getContextPath();
    111112    host = Application.getHostName();
    112     utf8 = Charset.forName("UTF-8");
     113    utf8 = StandardCharsets.UTF_8;
    113114    reset();
    114115  }
     
    141142    response.setContentType("application/rss+xml");
    142143    response.setContentLength(feed.length);
    143     response.setCharacterEncoding("UTF-8");
     144    response.setCharacterEncoding(utf8.name());
    144145    response.getOutputStream().write(feed);
    145146  }
  • trunk/src/core/net/sf/basedb/core/ExtendedPropertyLinker.java

    r4517 r7714  
    2222package net.sf.basedb.core;
    2323
    24 import java.io.UnsupportedEncodingException;
    2524import java.net.URLEncoder;
     25import java.nio.charset.StandardCharsets;
    2626import java.util.regex.Matcher;
    2727import java.util.regex.Pattern;
     
    5656    @return The link, or null if this linker doesn't match the value
    5757  */
    58   @SuppressWarnings("deprecation")
    5958  public String getUrl(Object value)
    6059  {
     
    6463      return null;
    6564    }
    66     try
    67     {
    68       return url.replaceAll(URLEncoder.encode(value.toString(), "UTF-8"));
    69     }
    70     catch (UnsupportedEncodingException ex)
    71     {
    72       return url.replaceAll(URLEncoder.encode(value.toString()));
    73     }
     65    return url.replaceAll(URLEncoder.encode(value.toString(), StandardCharsets.UTF_8));
    7466  }
    7567 
  • trunk/src/core/net/sf/basedb/core/File.java

    r7641 r7714  
    5757import java.net.URISyntaxException;
    5858import java.nio.charset.Charset;
     59import java.nio.charset.StandardCharsets;
    5960import java.text.SimpleDateFormat;
    6061import java.util.Date;
     
    16881689      {
    16891690        // Start a thread for parallell testing if the file can be parsed as UTF-8
    1690         utf8Tester = new CharsetTesterThread(Charset.forName("UTF-8"));
     1691        utf8Tester = new CharsetTesterThread(StandardCharsets.UTF_8);
    16911692        new Thread(utf8Tester).start();
    16921693      }
  • trunk/src/core/net/sf/basedb/core/HibernateUtil.java

    r7587 r7714  
    7979import java.io.IOException;
    8080import java.net.URL;
     81import java.nio.charset.StandardCharsets;
    8182
    8283import org.jdom2.Document;
     
    434435        cfg.addInputStream(new ByteArrayInputStreamAccess(
    435436          url.toString(),
    436           xml.getBytes("UTF-8")
     437          xml.getBytes(StandardCharsets.UTF_8)
    437438          ));
    438439      }
     
    710711          cfg.addInputStream(new ByteArrayInputStreamAccess(
    711712            templateFile.toString()+"?"+rdt.getEntityName(),
    712             out.outputString(dom).getBytes("UTF-8")));
     713            out.outputString(dom).getBytes(StandardCharsets.UTF_8)));
    713714        }
    714715        catch (Exception ex)
  • trunk/src/core/net/sf/basedb/core/Migration.java

    r7553 r7714  
    3535import java.io.StringWriter;
    3636import java.io.Writer;
     37import java.nio.charset.StandardCharsets;
    3738import java.sql.Connection;
    3839import java.sql.DatabaseMetaData;
     
    393394      File columnsFile = getColumnsFile(table);
    394395      // Create SELECT <columns> FROM <table>
    395       Writer writer = new OutputStreamWriter(FileUtil.getOutputStream(columnsFile), "UTF-8");
     396      Writer writer = new OutputStreamWriter(FileUtil.getOutputStream(columnsFile), StandardCharsets.UTF_8);
    396397      Statement st = connection.createStatement();
    397398      st.setFetchSize(columns.length < 10 ? fetchSize * 5 : fetchSize);
     
    437438        compressThread.start();
    438439      }
    439       writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
     440      writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
    440441     
    441442      // Setup writer factory and factories
     
    852853   
    853854    StringWriter sin = new StringWriter((int)columnsFile.length());
    854     FileUtil.copy(new InputStreamReader(FileUtil.getInputStream(columnsFile), "UTF-8"), sin);
     855    FileUtil.copy(new InputStreamReader(FileUtil.getInputStream(columnsFile), StandardCharsets.UTF_8), sin);
    855856    String[] columns = sin.toString().split(",");
    856857   
  • trunk/src/core/net/sf/basedb/core/plugin/AbstractPlugin.java

    r6127 r7714  
    3737import java.io.PrintWriter;
    3838import java.nio.charset.Charset;
     39import java.nio.charset.StandardCharsets;
    3940import java.util.Collection;
    4041import java.util.List;
     
    379380      File f = File.getByPath(logDc, p, true);
    380381      f.setMimeType("text/plain");
    381       Charset utf8 = Charset.forName("UTF-8");
     382      Charset utf8 = StandardCharsets.UTF_8;
    382383      f.setCharacterSet(utf8.name());
    383384      if (!f.isInDatabase()) logDc.saveItem(f);
  • trunk/src/core/net/sf/basedb/util/GeoLocation.java

    r7494 r7714  
    2525import java.io.InputStreamReader;
    2626import java.io.StringWriter;
    27 import java.io.UnsupportedEncodingException;
    2827import java.net.URI;
    2928import java.net.URLEncoder;
     29import java.nio.charset.StandardCharsets;
    3030
    3131import org.apache.commons.validator.routines.InetAddressValidator;
     
    5959    null is returned.
    6060  */
    61   @SuppressWarnings("deprecation")
    6261  public static GeoLocation getLocationFromIp(String ip)
    6362  {
     
    7069    if (url == null) return null;
    7170   
    72     try
    73     {
    74       url = url.replace("{IP}", URLEncoder.encode(ip, "UTF-8"));
    75     }
    76     catch (UnsupportedEncodingException ex)
    77     {
    78       url = url.replace("{IP}", URLEncoder.encode(ip));
    79     }
     71    url = url.replace("{IP}", URLEncoder.encode(ip, StandardCharsets.UTF_8));
    8072   
    8173    JSONObject jsonLoc = null;
     
    8981      in = http.getInputStream();
    9082      StringWriter sout = new StringWriter();
    91       FileUtil.copy(new InputStreamReader(in, "UTF-8"), sout, filter);
     83      FileUtil.copy(new InputStreamReader(in, StandardCharsets.UTF_8), sout, filter);
    9284      jsonLoc = (JSONObject)new JSONParser().parse(sout.toString());
    9385      in.close();
  • trunk/src/core/net/sf/basedb/util/MD5.java

    r4951 r7714  
    2727import java.security.MessageDigest;
    2828import java.math.BigInteger;
     29import java.nio.charset.StandardCharsets;
    2930
    3031/**
     
    4546    {
    4647      MessageDigest md5 = MessageDigest.getInstance("MD5");
    47       BigInteger result = new BigInteger(1, md5.digest(in.getBytes("UTF-8")));
     48      BigInteger result = new BigInteger(1, md5.digest(in.getBytes(StandardCharsets.UTF_8)));
    4849      return leftPad(result.toString(16), '0', 32);
    4950    }
  • trunk/src/core/net/sf/basedb/util/bcrypt/BCrypt.java

    r7052 r7714  
    1313//ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    1414//OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    15 import java.io.UnsupportedEncodingException;
     15
     16import java.nio.charset.StandardCharsets;
    1617import java.security.SecureRandom;
    1718
     
    671672
    672673    real_salt = salt.substring(off + 3, off + 25);
    673     try {
    674       passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8");
    675     } catch (UnsupportedEncodingException uee) {
    676       throw new AssertionError("UTF-8 is not supported");
    677     }
     674   
     675    passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes(StandardCharsets.UTF_8);
    678676
    679677    saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);
     
    759757    byte hashed_bytes[];
    760758    byte try_bytes[];
    761     try {
    762       String try_pw = hashpw(plaintext, hashed);
    763       hashed_bytes = hashed.getBytes("UTF-8");
    764       try_bytes = try_pw.getBytes("UTF-8");
    765     } catch (UnsupportedEncodingException uee) {
    766       return false;
    767     }
     759
     760    String try_pw = hashpw(plaintext, hashed);
     761    hashed_bytes = hashed.getBytes(StandardCharsets.UTF_8);
     762    try_bytes = try_pw.getBytes(StandardCharsets.UTF_8);
     763   
    768764    if (hashed_bytes.length != try_bytes.length)
    769765      return false;
  • trunk/src/core/net/sf/basedb/util/bfs/AbstractDataWriterFactory.java

    r5212 r7714  
    2525import java.io.OutputStream;
    2626import java.io.OutputStreamWriter;
    27 import java.nio.charset.Charset;
     27import java.nio.charset.StandardCharsets;
    2828import java.util.HashSet;
    2929import java.util.Set;
     
    7676    usedFiles.add(filename);
    7777    OutputStream out = getOutputStream(filename);
    78     DataWriter writer = new DataWriter(new OutputStreamWriter(out, Charset.forName("UTF-8")));
     78    DataWriter writer = new DataWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
    7979    writer.setFilename(filename);
    8080    return writer;
  • trunk/src/core/net/sf/basedb/util/bfs/AnnotationWriter.java

    r5384 r7714  
    2828import java.io.OutputStreamWriter;
    2929import java.io.Writer;
    30 import java.nio.charset.Charset;
     30import java.nio.charset.StandardCharsets;
    3131import java.util.HashSet;
    3232import java.util.Set;
     
    5757    if (out == null) throw new NullPointerException("out");
    5858    AnnotationWriter writer = new AnnotationWriter(
    59         new OutputStreamWriter(out, Charset.forName("UTF-8")));
     59        new OutputStreamWriter(out, StandardCharsets.UTF_8));
    6060    writer.setFilename(filename);
    6161    return writer;
  • trunk/src/core/net/sf/basedb/util/bfs/DataWriter.java

    r5384 r7714  
    2828import java.io.OutputStreamWriter;
    2929import java.io.Writer;
    30 import java.nio.charset.Charset;
     30import java.nio.charset.StandardCharsets;
    3131
    3232import net.sf.basedb.core.File;
     
    6161    if (out == null) throw new NullPointerException("out");
    6262    DataWriter writer = new DataWriter(
    63         new OutputStreamWriter(out, Charset.forName("UTF-8")));
     63        new OutputStreamWriter(out, StandardCharsets.UTF_8));
    6464    writer.setFilename(filename);
    6565    return writer;
  • trunk/src/core/net/sf/basedb/util/bfs/MetadataWriter.java

    r6125 r7714  
    2929import java.io.PrintWriter;
    3030import java.io.Writer;
    31 import java.nio.charset.Charset;
     31import java.nio.charset.StandardCharsets;
    3232import java.util.HashSet;
    3333import java.util.Set;
     
    7373    if (out == null) throw new NullPointerException("out");
    7474    MetadataWriter writer = new MetadataWriter(
    75         new OutputStreamWriter(out, Charset.forName("UTF-8")));
     75        new OutputStreamWriter(out, StandardCharsets.UTF_8));
    7676    writer.setFilename(filename);
    7777    return writer;
  • trunk/src/core/net/sf/basedb/util/excel/XlsxToCsvUtil.java

    r7703 r7714  
    55import java.io.InputStream;
    66import java.nio.charset.Charset;
     7import java.nio.charset.StandardCharsets;
    78import java.text.NumberFormat;
    89import java.util.ArrayList;
     
    113114    this.writeTrailingColumns = true;
    114115    this.evaluateFormulas = false;
    115     this.charset = Charset.forName("UTF-8");
     116    this.charset = StandardCharsets.UTF_8;
    116117    this.encoder = new ToSpaceEncoderDecoder();
    117118    this.sheets = new HashMap<>();
  • trunk/src/core/net/sf/basedb/util/resources/Utf8PropertiesResourceBundleControl.java

    r5823 r7714  
    2525import java.io.InputStream;
    2626import java.io.InputStreamReader;
     27import java.nio.charset.StandardCharsets;
    2728import java.util.List;
    2829import java.util.Locale;
     
    100101      if (in != null)
    101102      {
    102         bundle = new PropertyResourceBundle(new InputStreamReader(in, "UTF-8"));
     103        bundle = new PropertyResourceBundle(new InputStreamReader(in, StandardCharsets.UTF_8));
    103104      }
    104105    }
  • trunk/src/plugins/core/net/sf/basedb/plugins/HelpImporter.java

    r6473 r7714  
    3030import java.net.URL;
    3131import java.nio.charset.Charset;
     32import java.nio.charset.StandardCharsets;
    3233import java.util.ArrayList;
    3334import java.util.Arrays;
     
    288289      charset = ((ImportInputStream)in).getCharacterSet();
    289290    }
    290     if (charset == null) charset = "UTF-8";
    291291    BufferedReader reader = new BufferedReader(
    292         new InputStreamReader(in, Charset.forName(charset)));
     292        new InputStreamReader(in, charset == null ? StandardCharsets.UTF_8 : Charset.forName(charset)));
    293293    try
    294294    {
  • trunk/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationExporter.java

    r7605 r7714  
    5858import java.io.OutputStreamWriter;
    5959import java.io.Writer;
     60import java.nio.charset.StandardCharsets;
    6061import java.util.ArrayList;
    6162import java.util.Arrays;
     
    259260      // Initialize the XML-document     
    260261      XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8"));
    261       Writer configurationExportStream = new OutputStreamWriter(out, "UTF-8");
     262      Writer configurationExportStream = new OutputStreamWriter(out, StandardCharsets.UTF_8);
    262263      configurationExportStream.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    263264      xmlOut.output(new DocType("configfile", "plugin-configuration-file.dtd"), configurationExportStream);
  • trunk/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationImporter.java

    r6880 r7714  
    5555import java.io.InputStreamReader;
    5656import java.nio.charset.Charset;
     57import java.nio.charset.StandardCharsets;
    5758import java.util.ArrayList;
    5859import java.util.Arrays;
     
    301302      charset = ((ImportInputStream)in).getCharacterSet();
    302303    }
    303     if (charset == null) charset = "UTF-8";
    304304    BufferedReader reader = new BufferedReader(
    305         new InputStreamReader(in, Charset.forName(charset)));
     305        new InputStreamReader(in, charset == null ? StandardCharsets.UTF_8 : Charset.forName(charset)));
    306306    try
    307307    {
  • trunk/src/test/TestBfs.java

    r5221 r7714  
    2626import java.io.OutputStreamWriter;
    2727import java.io.Writer;
     28import java.nio.charset.StandardCharsets;
    2829import java.util.Arrays;
    2930
     
    262263      if (copyTo != null)
    263264      {
    264         bfs.print(new OutputStreamWriter(new FileOutputStream(copyTo), "UTF-8"));
     265        bfs.print(new OutputStreamWriter(new FileOutputStream(copyTo), StandardCharsets.UTF_8));
    265266      }
    266267     
Note: See TracChangeset for help on using the changeset viewer.