本文整理匯總了Java中net.sourceforge.subsonic.util.StringUtil類的典型用法代碼示例。如果您正苦於以下問題:Java StringUtil類的具體用法?Java StringUtil怎麽用?Java StringUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StringUtil類屬於net.sourceforge.subsonic.util包,在下文中一共展示了StringUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encode
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
private String encode(String s) throws UnsupportedEncodingException {
if (isUtf8Hex()) {
if (isAsciiAlphaNumeric(s)) {
return s;
}
try {
return StringUtil.utf8HexEncode(s);
} catch (Exception x) {
LOG.error("Failed to utf8hex-encode the string '" + s + "'.", x);
return s;
}
}
return URLEncoder.encode(s, encoding);
}
示例2: sendFallback
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
private void sendFallback(Integer size, HttpServletResponse response) throws IOException {
if (response.getContentType() == null) {
response.setContentType(StringUtil.getMimeType("jpeg"));
}
InputStream in = null;
try {
in = getClass().getResourceAsStream("default_cover.jpg");
BufferedImage image = ImageIO.read(in);
if (size != null) {
image = scale(image, size, size);
}
ImageIO.write(image, "jpeg", response.getOutputStream());
} finally {
IOUtils.closeQuietly(in);
}
}
示例3: handleRequest
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setContentType("audio/x-mpegurl");
response.setCharacterEncoding(StringUtil.ENCODING_UTF8);
Player player = playerService.getPlayer(request, response);
String url = request.getRequestURL().toString();
url = url.replaceFirst("play.m3u.*", "stream?");
// Rewrite URLs in case we're behind a proxy.
if (settingsService.isRewriteUrlEnabled()) {
String referer = request.getHeader("referer");
url = StringUtil.rewriteUrl(url, referer);
}
url = settingsService.rewriteRemoteUrl(url);
if (player.isExternalWithPlaylist()) {
createClientSidePlaylist(response.getWriter(), player, url);
} else {
createServerSidePlaylist(response.getWriter(), player, url);
}
return null;
}
示例4: login
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {
// Auto-login if "user" and "password" parameters are given.
String username = request.getParameter("user");
String password = request.getParameter("password");
if (username != null && password != null) {
username = StringUtil.urlEncode(username);
password = StringUtil.urlEncode(password);
return new ModelAndView(new RedirectView("j_acegi_security_check?j_username=" + username +
"&j_password=" + password + "&_acegi_security_remember_me=checked"));
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("logout", request.getParameter("logout") != null);
map.put("error", request.getParameter("error") != null);
map.put("brand", settingsService.getBrand());
map.put("loginMessage", settingsService.getLoginMessage());
User admin = securityService.getUserByName(User.USERNAME_ADMIN);
if (User.USERNAME_ADMIN.equals(admin.getPassword())) {
map.put("insecure", true);
}
return new ModelAndView("login", "model", map);
}
示例5: getFile
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
private synchronized File getFile(PodcastChannel channel, PodcastEpisode episode) {
File channelDir = getChannelDirectory(channel);
String filename = StringUtil.getUrlFile(episode.getUrl());
if (filename == null) {
filename = episode.getTitle();
}
filename = StringUtil.fileSystemSafe(filename);
String extension = FilenameUtils.getExtension(filename);
filename = FilenameUtils.removeExtension(filename);
if (StringUtils.isBlank(extension)) {
extension = "mp3";
}
File file = new File(channelDir, filename + "." + extension);
for (int i = 0; file.exists(); i++) {
file = new File(channelDir, filename + i + "." + extension);
}
if (!securityService.isWriteAllowed(file)) {
throw new SecurityException("Access denied to file " + file);
}
return file;
}
示例6: getChannelDirectory
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
private File getChannelDirectory(PodcastChannel channel) {
File podcastDir = new File(settingsService.getPodcastFolder());
File channelDir = new File(podcastDir, StringUtil.fileSystemSafe(channel.getTitle()));
if (!channelDir.exists()) {
boolean ok = channelDir.mkdirs();
if (!ok) {
throw new RuntimeException("Failed to create directory " + channelDir);
}
MediaFile mediaFile = mediaFileService.getMediaFile(channelDir);
mediaFile.setComment(channel.getDescription());
mediaFileService.updateMediaFile(mediaFile);
}
return channelDir;
}
示例7: getAvailableThemes
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
/**
* Returns a list of available themes.
*
* @return A list of available themes.
*/
public synchronized Theme[] getAvailableThemes() {
if (themes == null) {
themes = new ArrayList<Theme>();
try {
InputStream in = SettingsService.class.getResourceAsStream(THEMES_FILE);
String[] lines = StringUtil.readLines(in);
for (String line : lines) {
String[] elements = StringUtil.split(line);
if (elements.length == 2) {
themes.add(new Theme(elements[0], elements[1]));
} else if (elements.length == 3) {
themes.add(new Theme(elements[0], elements[1], elements[2]));
} else {
LOG.warn("Failed to parse theme from line: [" + line + "].");
}
}
} catch (IOException x) {
LOG.error("Failed to resolve list of themes.", x);
themes.add(new Theme("default", "Subsonic default"));
}
}
return themes.toArray(new Theme[themes.size()]);
}
示例8: getAvailableLocales
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
/**
* Returns a list of available locales.
*
* @return A list of available locales.
*/
public synchronized Locale[] getAvailableLocales() {
if (locales == null) {
locales = new ArrayList<Locale>();
try {
InputStream in = SettingsService.class.getResourceAsStream(LOCALES_FILE);
String[] lines = StringUtil.readLines(in);
for (String line : lines) {
locales.add(parseLocale(line));
}
} catch (IOException x) {
LOG.error("Failed to resolve list of locales.", x);
locales.add(Locale.ENGLISH);
}
}
return locales.toArray(new Locale[locales.size()]);
}
示例9: decode
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
private String[] decode(String[] values) {
if (values == null) {
return null;
}
String[] result = new String[values.length];
for (int i = 0; i < values.length; i++) {
try {
result[i] = StringUtil.utf8HexDecode(values[i]);
} catch (Exception x) {
LOG.error("Failed to decode parameter value '" + values[i] + "'");
result[i] = values[i];
}
}
return result;
}
示例10: isExcluded
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
/**
* Returns whether the given file is excluded, i.e., whether it is listed in 'madsonic_exclude.txt' in
* the current directory.
*
* @param file The child file in question.
* @return Whether the child file is excluded.
*/
private boolean isExcluded(File file) throws IOException {
if (file.getName().startsWith(".") || file.getName().startsWith("@eaDir") || file.getName().toLowerCase().equals("thumbs.db") || file.getName().toLowerCase().equals("extrafanart") ) {
return true;
}
File excludeFile = new File(file.getParentFile().getPath(), "madsonic_exclude.txt");
if (excludeFile.exists()) {
excludes = new HashSet<String>();
LOG.debug("## excludeFile found: " + excludeFile);
String[] lines = StringUtil.readLines(new FileInputStream(excludeFile));
for (String line : lines) {
excludes.add(line.toLowerCase());
}
return excludes.contains(file.getName().toLowerCase());
}
return false;
}
示例11: reload
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
private ModelAndView reload(String dir) {
List<ReloadFrame> reloadFrames = new ArrayList<ReloadFrame>();
reloadFrames.add(new ReloadFrame("playQueue", "playQueue.view?"));
if (dir == null) {
reloadFrames.add(new ReloadFrame("main", "nowPlaying.view?"));
} else {
reloadFrames.add(new ReloadFrame("main", "main.view?pathUtf8Hex=" + StringUtil.utf8HexEncode(dir)));
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("reloadFrames", reloadFrames);
return new ModelAndView("reload", "model", map);
}
示例12: handleParameters
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
private void handleParameters(HttpServletRequest request) {
if (request.getParameter("add") != null) {
String url = StringUtils.trim(request.getParameter("add"));
podcastService.createChannel(url);
}
if (request.getParameter("downloadChannel") != null ||
request.getParameter("downloadEpisode") != null) {
download(StringUtil.parseInts(request.getParameter("downloadChannel")),
StringUtil.parseInts(request.getParameter("downloadEpisode")));
}
if (request.getParameter("deleteChannel") != null) {
for (int channelId : StringUtil.parseInts(request.getParameter("deleteChannel"))) {
podcastService.deleteChannel(channelId);
}
}
if (request.getParameter("deleteEpisode") != null) {
for (int episodeId : StringUtil.parseInts(request.getParameter("deleteEpisode"))) {
podcastService.deleteEpisode(episodeId, true);
}
}
if (request.getParameter("refresh") != null) {
podcastService.refreshAllChannels(true);
}
}
示例13: sendDefault
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
private void sendDefault(Integer size, HttpServletResponse response) throws IOException {
if (response.getContentType() == null) {
response.setContentType(StringUtil.getMimeType("png"));
}
InputStream in = null;
try {
in = getClass().getResourceAsStream("default_cover.png");
BufferedImage image = ImageIO.read(in);
if (size != null) {
image = scale(image, size, size);
}
ImageIO.write(image, "png", response.getOutputStream());
} finally {
IOUtils.closeQuietly(in);
}
}
示例14: getLicense
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
public void getLicense(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
XMLBuilder builder = createXMLBuilder(request, response, true);
String email = settingsService.getLicenseEmail();
String key = settingsService.getLicenseCode();
Date date = settingsService.getLicenseDate();
boolean valid = settingsService.isLicenseValid();
AttributeSet attributes = new AttributeSet();
attributes.add("valid", valid);
if (valid) {
attributes.add("email", email);
attributes.add("key", key);
attributes.add("date", StringUtil.toISO8601(date));
}
builder.add("license", attributes, true);
builder.endAll();
response.getWriter().print(builder);
}
示例15: sendAutoGenerated
import net.sourceforge.subsonic.util.StringUtil; //導入依賴的package包/類
private void sendAutoGenerated(Integer size, MediaFile mediaFile, HttpServletResponse response) throws IOException {
if (mediaFile.isFile()) {
mediaFile = mediaFileService.getParentOf(mediaFile);
}
if (size == null) {
size = CoverArtScheme.MEDIUM.getSize() * 2;
}
BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = image.createGraphics();
AutoCover autoCover = new AutoCover(graphics, mediaFile, size);
autoCover.paintCover();
graphics.dispose();
response.setContentType(StringUtil.getMimeType("png"));
ImageIO.write(image, "png", response.getOutputStream());
}