Use a constant for encoding
Replace string.getBytes("UTF-8") with
string.getBytes(CONSTANT).
This commit is contained in:
@@ -41,6 +41,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -178,7 +179,7 @@ public class DownloadController implements LastModified {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String encodeAsRFC5987(String string) throws UnsupportedEncodingException {
|
private String encodeAsRFC5987(String string) throws UnsupportedEncodingException {
|
||||||
byte[] stringAsByteArray = string.getBytes("UTF-8");
|
byte[] stringAsByteArray = string.getBytes(StandardCharsets.UTF_8);
|
||||||
char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||||
byte[] attrChar = {'!', '#', '$', '&', '+', '-', '.', '^', '_', '`', '|', '~', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
|
byte[] attrChar = {'!', '#', '$', '&', '+', '-', '.', '^', '_', '`', '|', '~', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements SHOUTcast support by decorating an existing output stream.
|
* Implements SHOUTcast support by decorating an existing output stream.
|
||||||
@@ -188,7 +189,7 @@ public class ShoutCastOutputStream extends OutputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
title = "StreamTitle='" + title + "';";
|
title = "StreamTitle='" + title + "';";
|
||||||
return title.getBytes("US-ASCII");
|
return title.getBytes(StandardCharsets.US_ASCII);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -385,11 +386,7 @@ public final class StringUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
byte[] utf8;
|
byte[] utf8;
|
||||||
try {
|
utf8 = s.getBytes(StandardCharsets.UTF_8);
|
||||||
utf8 = s.getBytes(ENCODING_UTF8);
|
|
||||||
} catch (UnsupportedEncodingException x) {
|
|
||||||
throw new RuntimeException(x);
|
|
||||||
}
|
|
||||||
return String.valueOf(Hex.encodeHex(utf8));
|
return String.valueOf(Hex.encodeHex(utf8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +401,7 @@ public final class StringUtil {
|
|||||||
if (s == null) {
|
if (s == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new String(Hex.decodeHex(s.toCharArray()), ENCODING_UTF8);
|
return new String(Hex.decodeHex(s.toCharArray()), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -420,7 +417,7 @@ public final class StringUtil {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||||
return new String(Hex.encodeHex(md5.digest(s.getBytes(ENCODING_UTF8))));
|
return new String(Hex.encodeHex(md5.digest(s.getBytes(StandardCharsets.UTF_8))));
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
throw new RuntimeException(x.getMessage(), x);
|
throw new RuntimeException(x.getMessage(), x);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -25,6 +25,7 @@ import org.mockito.stubbing.Answer;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -93,7 +94,7 @@ public class PlaylistServiceTestImport {
|
|||||||
builder.append(mf3.getAbsolutePath()).append("\n");
|
builder.append(mf3.getAbsolutePath()).append("\n");
|
||||||
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
|
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
|
||||||
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
|
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
|
||||||
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
|
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
String path = "/path/to/"+playlistName+".m3u";
|
String path = "/path/to/"+playlistName+".m3u";
|
||||||
playlistService.importPlaylist(username, playlistName, path, inputStream, null);
|
playlistService.importPlaylist(username, playlistName, path, inputStream, null);
|
||||||
verify(playlistDao).createPlaylist(actual.capture());
|
verify(playlistDao).createPlaylist(actual.capture());
|
||||||
@@ -127,7 +128,7 @@ public class PlaylistServiceTestImport {
|
|||||||
builder.append("File3=").append(mf3.getAbsolutePath()).append("\n");
|
builder.append("File3=").append(mf3.getAbsolutePath()).append("\n");
|
||||||
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
|
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
|
||||||
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
|
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
|
||||||
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
|
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
String path = "/path/to/"+playlistName+".pls";
|
String path = "/path/to/"+playlistName+".pls";
|
||||||
playlistService.importPlaylist(username, playlistName, path, inputStream, null);
|
playlistService.importPlaylist(username, playlistName, path, inputStream, null);
|
||||||
verify(playlistDao).createPlaylist(actual.capture());
|
verify(playlistDao).createPlaylist(actual.capture());
|
||||||
@@ -164,7 +165,7 @@ public class PlaylistServiceTestImport {
|
|||||||
builder.append(" </trackList>\n" + "</playlist>\n");
|
builder.append(" </trackList>\n" + "</playlist>\n");
|
||||||
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
|
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
|
||||||
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
|
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
|
||||||
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
|
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
String path = "/path/to/"+playlistName+".xspf";
|
String path = "/path/to/"+playlistName+".xspf";
|
||||||
playlistService.importPlaylist(username, playlistName, path, inputStream, null);
|
playlistService.importPlaylist(username, playlistName, path, inputStream, null);
|
||||||
verify(playlistDao).createPlaylist(actual.capture());
|
verify(playlistDao).createPlaylist(actual.capture());
|
||||||
|
|||||||
Reference in New Issue
Block a user