當前位置: 首頁>>代碼示例>>Java>>正文


Java Util類代碼示例

本文整理匯總了Java中net.sourceforge.subsonic.util.Util的典型用法代碼示例。如果您正苦於以下問題:Java Util類的具體用法?Java Util怎麽用?Java Util使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Util類屬於net.sourceforge.subsonic.util包,在下文中一共展示了Util類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: savePlayQueue

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
@SuppressWarnings("UnusedDeclaration")
public void savePlayQueue(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);
    List<Integer> mediaFileIds = Util.toIntegerList(getIntParameters(request, "id"));
    Integer current = getIntParameter(request, "current");
    Long position = getLongParameter(request, "position");
    Date changed = new Date();
    String changedBy = getRequiredStringParameter(request, "c");

    if (!mediaFileIds.contains(current)) {
        error(request, response, ErrorCode.GENERIC, "Current track is not included in play queue");
        return;
    }

    SavedPlayQueue playQueue = new SavedPlayQueue(null, username, mediaFileIds, current, position, changed, changedBy);
    playQueueDao.savePlayQueue(playQueue);
    writeEmptyResponse(request, response);
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:20,代碼來源:RESTController.java

示例2: resetCommand

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
private void resetCommand(UserSettingsCommand command) {
    command.setUser(null);
    command.setUsers(securityService.getAllUsers());
    command.setDeleteUser(false);
    command.setPasswordChange(false);
    command.setNewUser(true);
    command.setStreamRole(true);
    command.setSettingsRole(true);
    command.setPassword(null);
    command.setConfirmPassword(null);
    command.setEmail(null);
    command.setTranscodeSchemeName(null);
    command.setAllMusicFolders(settingsService.getAllMusicFolders());
    command.setAllowedMusicFolderIds(Util.toIntArray(getAllowedMusicFolderIds(null)));
    command.setToast(true);
    command.setReload(true);
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:18,代碼來源:UserSettingsController.java

示例3: getBaseUrl

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
protected String getBaseUrl() {
    int port = settingsService.getPort();
    int httpsPort = settingsService.getHttpsPort();
    boolean isHttps = httpsPort != 0;
    String contextPath = settingsService.getUrlRedirectContextPath();

    StringBuilder url = new StringBuilder(isHttps ? "https://" : "http://")
            .append(Util.getLocalIpAddress())
            .append(":")
            .append(isHttps ? httpsPort : port)
            .append("/");

    if (StringUtils.isNotEmpty(contextPath)) {
        url.append(contextPath).append("/");
    }
    return url.toString();
}
 
開發者ID:FutureSonic,項目名稱:FutureSonic-Server,代碼行數:18,代碼來源:SubsonicContentDirectory.java

示例4: normalizePath

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
/**
 * Paths in an external playlist may not have the same upper/lower case as in the (case sensitive) media_file table.
 * This methods attempts to normalize the external path to match the one stored in the table.
 */
private File normalizePath(File file) throws IOException {

    // Only relevant for Windows where paths are case insensitive.
    if (!Util.isWindows()) {
        return file;
    }

    // Find the most specific music folder.
    String canonicalPath = file.getCanonicalPath();
    MusicFolder containingMusicFolder = null;
    for (MusicFolder musicFolder : settingsService.getAllMusicFolders()) {
        String musicFolderPath = musicFolder.getPath().getPath();
        if (canonicalPath.toLowerCase().startsWith(musicFolderPath.toLowerCase())) {
            if (containingMusicFolder == null || containingMusicFolder.getPath().length() < musicFolderPath.length()) {
                containingMusicFolder = musicFolder;
            }
        }
    }
   if (containingMusicFolder == null) {
        return null;
    }

    return new File(containingMusicFolder.getPath().getPath() + canonicalPath.substring(containingMusicFolder.getPath().getPath().length()));
    // TODO: Consider slashes.
}
 
開發者ID:FutureSonic,項目名稱:FutureSonic-Server,代碼行數:30,代碼來源:PlaylistService.java

示例5: createUser

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
@SuppressWarnings("UnusedDeclaration")
public void createUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    if (!user.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to create new users.");
        return;
    }

    UserSettingsCommand command = new UserSettingsCommand();
    command.setUsername(getRequiredStringParameter(request, "username"));
    command.setPassword(decrypt(getRequiredStringParameter(request, "password")));
    command.setEmail(getRequiredStringParameter(request, "email"));
    command.setLdapAuthenticated(getBooleanParameter(request, "ldapAuthenticated", false));
    command.setAdminRole(getBooleanParameter(request, "adminRole", false));
    command.setCommentRole(getBooleanParameter(request, "commentRole", false));
    command.setCoverArtRole(getBooleanParameter(request, "coverArtRole", false));
    command.setDownloadRole(getBooleanParameter(request, "downloadRole", false));
    command.setStreamRole(getBooleanParameter(request, "streamRole", true));
    command.setUploadRole(getBooleanParameter(request, "uploadRole", false));
    command.setJukeboxRole(getBooleanParameter(request, "jukeboxRole", false));
    command.setPodcastRole(getBooleanParameter(request, "podcastRole", false));
    command.setSettingsRole(getBooleanParameter(request, "settingsRole", true));
    command.setShareRole(getBooleanParameter(request, "shareRole", false));
    command.setTranscodeSchemeName(TranscodeScheme.OFF.name());

    int[] folderIds = ServletRequestUtils.getIntParameters(request, "musicFolderId");
    if (folderIds.length == 0) {
        folderIds = Util.toIntArray(MusicFolder.toIdList(settingsService.getAllMusicFolders()));
    }
    command.setAllowedMusicFolderIds(folderIds);

    userSettingsController.createUser(command);
    writeEmptyResponse(request, response);
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:36,代碼來源:RESTController.java

示例6: downloadFile

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
/**
 * Downloads a single file.
 *
 *
 * @param response The HTTP response.
 * @param status   The download status.
 * @param file     The file to download.
 * @param range    The byte range, may be <code>null</code>.
 * @throws IOException If an I/O error occurs.
 */
private void downloadFile(HttpServletResponse response, TransferStatus status, File file, HttpRange range) throws IOException {
    LOG.info("Starting to download '" + FileUtil.getShortPath(file) + "' to " + status.getPlayer());
    status.setFile(file);

    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodeAsRFC5987(file.getName()));
    if (range == null) {
        Util.setContentLength(response, file.length());
    }

    copyFileToStream(file, RangeOutputStream.wrap(response.getOutputStream(), range), status, range);
    LOG.info("Downloaded '" + FileUtil.getShortPath(file) + "' to " + status.getPlayer());
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:24,代碼來源:DownloadController.java

示例7: formBackingObject

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
@Override
protected Object formBackingObject(HttpServletRequest request) throws Exception {
    UserSettingsCommand command = new UserSettingsCommand();

    User user = getUser(request);
    if (user != null) {
        command.setUser(user);
        command.setEmail(user.getEmail());
        command.setAdmin(User.USERNAME_ADMIN.equals(user.getUsername()));
        UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
        command.setTranscodeSchemeName(userSettings.getTranscodeScheme().name());

    } else {
        command.setNewUser(true);
        command.setStreamRole(true);
        command.setSettingsRole(true);
    }

    command.setUsers(securityService.getAllUsers());
    command.setTranscodingSupported(transcodingService.isDownsamplingSupported(null));
    command.setTranscodeDirectory(transcodingService.getTranscodeDirectory().getPath());
    command.setTranscodeSchemes(TranscodeScheme.values());
    command.setLdapEnabled(settingsService.isLdapEnabled());
    command.setAllMusicFolders(settingsService.getAllMusicFolders());
    command.setAllowedMusicFolderIds(Util.toIntArray(getAllowedMusicFolderIds(user)));

    return command;
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:29,代碼來源:UserSettingsController.java

示例8: updateUser

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
public void updateUser(UserSettingsCommand command) {
    User user = securityService.getUserByName(command.getUsername());
    user.setEmail(StringUtils.trimToNull(command.getEmail()));
    user.setLdapAuthenticated(command.isLdapAuthenticated());
    user.setAdminRole(command.isAdminRole());
    user.setDownloadRole(command.isDownloadRole());
    user.setUploadRole(command.isUploadRole());
    user.setCoverArtRole(command.isCoverArtRole());
    user.setCommentRole(command.isCommentRole());
    user.setPodcastRole(command.isPodcastRole());
    user.setStreamRole(command.isStreamRole());
    user.setJukeboxRole(command.isJukeboxRole());
    user.setSettingsRole(command.isSettingsRole());
    user.setShareRole(command.isShareRole());

    if (command.isPasswordChange()) {
        user.setPassword(command.getPassword());
    }

    securityService.updateUser(user);

    UserSettings userSettings = settingsService.getUserSettings(command.getUsername());
    userSettings.setTranscodeScheme(TranscodeScheme.valueOf(command.getTranscodeSchemeName()));
    userSettings.setChanged(new Date());
    settingsService.updateUserSettings(userSettings);

    List<Integer> allowedMusicFolderIds = Util.toIntegerList(command.getAllowedMusicFolderIds());
    settingsService.setMusicFoldersForUser(command.getUsername(), allowedMusicFolderIds);
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:30,代碼來源:UserSettingsController.java

示例9: browsePlaylistRoot

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
private BrowseResult browsePlaylistRoot(long firstResult, long maxResults) throws Exception {
    DIDLContent didl = new DIDLContent();
    List<Playlist> allPlaylists = playlistService.getAllPlaylists();
    List<Playlist> selectedPlaylists = Util.subList(allPlaylists, firstResult, maxResults);
    for (Playlist playlist : selectedPlaylists) {
        didl.addContainer(createPlaylistContainer(playlist));
    }

    return createBrowseResult(didl, selectedPlaylists.size(), allPlaylists.size());
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:11,代碼來源:FolderBasedContentDirectory.java

示例10: browsePlaylist

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
private BrowseResult browsePlaylist(Playlist playlist, long firstResult, long maxResults) throws Exception {
    List<MediaFile> allChildren = playlistService.getFilesInPlaylist(playlist.getId());
    List<MediaFile> selectedChildren = Util.subList(allChildren, firstResult, maxResults);

    DIDLContent didl = new DIDLContent();
    for (MediaFile child : selectedChildren) {
        addContainerOrItem(didl, child);
    }
    return createBrowseResult(didl, selectedChildren.size(), allChildren.size());
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:11,代碼來源:FolderBasedContentDirectory.java

示例11: browseRoot

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
private BrowseResult browseRoot(long firstResult, long maxResults) throws Exception {
    DIDLContent didl = new DIDLContent();
    List<MusicFolder> allFolders = settingsService.getAllMusicFolders();
    List<MusicFolder> selectedFolders = Util.subList(allFolders, firstResult, maxResults);
    for (MusicFolder folder : selectedFolders) {
        MediaFile mediaFile = mediaFileService.getMediaFile(folder.getPath());
        addContainerOrItem(didl, mediaFile);
    }

    if (maxResults > selectedFolders.size()) {
        didl.addContainer(createPlaylistRootContainer());
    }

    return createBrowseResult(didl, (int) didl.getCount(), allFolders.size() + 1);
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:16,代碼來源:FolderBasedContentDirectory.java

示例12: browseMediaFile

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
private BrowseResult browseMediaFile(MediaFile mediaFile, long firstResult, long maxResults) throws Exception {
    List<MediaFile> allChildren = mediaFileService.getChildrenOf(mediaFile, true, true, true);
    List<MediaFile> selectedChildren = Util.subList(allChildren, firstResult, maxResults);

    DIDLContent didl = new DIDLContent();
    for (MediaFile child : selectedChildren) {
        addContainerOrItem(didl, child);
    }
    return createBrowseResult(didl, selectedChildren.size(), allChildren.size());
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:11,代碼來源:FolderBasedContentDirectory.java

示例13: normalizePath

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
/**
 * Paths in an external playlist may not have the same upper/lower case as in the (case sensitive) media_file table.
 * This methods attempts to normalize the external path to match the one stored in the table.
 */
private File normalizePath(File file) throws IOException {

    // Only relevant for Windows where paths are case insensitive.
    if (!Util.isWindows()) {
        return file;
    }

    // Find the most specific music folder.
    String canonicalPath = file.getCanonicalPath();
    MusicFolder containingMusicFolder = null;
    for (MusicFolder musicFolder : settingsService.getAllMusicFolders()) {
        String musicFolderPath = musicFolder.getPath().getPath();
        if (canonicalPath.toLowerCase().startsWith(musicFolderPath.toLowerCase())) {
            if (containingMusicFolder == null || containingMusicFolder.getPath().length() < musicFolderPath.length()) {
                containingMusicFolder = musicFolder;
            }
        }
    }

    if (containingMusicFolder == null) {
        return null;
    }

    return new File(containingMusicFolder.getPath().getPath() + canonicalPath.substring(containingMusicFolder.getPath().getPath().length()));
    // TODO: Consider slashes.
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:31,代碼來源:PlaylistService.java

示例14: scheduleLocalIpAddressLookup

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
private void scheduleLocalIpAddressLookup() {
    Runnable task = new Runnable() {
        public void run() {
            localIpAddress = Util.getLocalIpAddress();
        }
    };
    executor.scheduleWithFixedDelay(task, 0L, LOCAL_IP_LOOKUP_DELAY_SECONDS, TimeUnit.SECONDS);
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:9,代碼來源:SettingsService.java

示例15: createSubList

import net.sourceforge.subsonic.util.Util; //導入依賴的package包/類
public static MediaList createSubList(int index, int count, List<? extends AbstractMedia> mediaCollections) {
    MediaList result = new MediaList();
    List<? extends AbstractMedia> selectedMediaCollections = Util.subList(mediaCollections, index, count);

    result.setIndex(index);
    result.setCount(selectedMediaCollections.size());
    result.setTotal(mediaCollections.size());
    result.getMediaCollectionOrMediaMetadata().addAll(selectedMediaCollections);

    return result;
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:12,代碼來源:SonosHelper.java


注:本文中的net.sourceforge.subsonic.util.Util類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。