当前位置: 首页>>代码示例>>Java>>正文


Java NetworkException类代码示例

本文整理汇总了Java中net.dean.jraw.http.NetworkException的典型用法代码示例。如果您正苦于以下问题:Java NetworkException类的具体用法?Java NetworkException怎么用?Java NetworkException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NetworkException类属于net.dean.jraw.http包,在下文中一共展示了NetworkException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scanReddit

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
public ArrayList<String> scanReddit(AuthHelper helper, ArrayList<String> links) throws NetworkException, OAuthException {
	RedditClient redditClient = helper.getRedditClient();
	SubredditPaginator doto = new SubredditPaginator(redditClient,"dota2");
	doto.setLimit(100);                    
	doto.setTimePeriod(TimePeriod.ALL);
	doto.setSorting(Sorting.NEW); 
	Listing<Submission> submissions = doto.next();
	String linkUrl = null;
	System.out.println("OK2");
	for(Submission s : submissions){
		linkUrl = s.getUrl();
		System.out.println(linkUrl);
		if(linkUrl.contains("oddshot") && !links.contains(linkUrl)){
			Scanner.submissionList.add(s);
			links.add(linkUrl);
		}
	}
	return links;
}
 
开发者ID:ashwinswaroop,项目名称:YouTubeBot,代码行数:20,代码来源:Scanner.java

示例2: onHandleIntent

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.cancel(intent.getIntExtra(NOTIFICATION_ID, -1));

    String[] messages = null;
    Bundle extras = intent.getExtras();
    if (extras != null) messages = extras.getStringArray(CheckForMail.MESSAGE_EXTRA);

    InboxManager inboxManager = new InboxManager(Authentication.reddit);

    if (messages != null && NetworkUtil.isConnected(getBaseContext())) {
        for (String message : messages) {
            try {
                inboxManager.setRead(message, true);
            } catch (NetworkException e) {
                e.printStackTrace();
                return;
            }
        }
    }

}
 
开发者ID:ccrama,项目名称:Slide,代码行数:24,代码来源:MarkAsReadService.java

示例3: onPastaCommand

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
@Command(aliases = {"pasta", "copypasta"}, description = "Gets a random copypasta from /r/copypasta.", usage = "pasta")
public static String onPastaCommand(String[] args, IMessage message) throws OAuthException, RateLimitException, DiscordException, MissingPermissionsException {
    Listing<Submission> copypasta = null;
    RedditClient redditClient;
    try {
        redditClient = Reddit.getRedditClient();
        if (!redditClient.isAuthenticated()) {
            Reddit.authReddit();
        }
        FluentRedditClient fluent = new FluentRedditClient(redditClient);
        copypasta = fluent.subreddit("copypasta").fetch();
    }   catch (NetworkException | NullPointerException e) {
        Reddit.authReddit();
        onPastaCommand(args, message);
    }

    System.out.println("Serving some pasta.");
    Random random = new Random();
    if (copypasta != null) {
        Submission pasta = copypasta.get(random.nextInt(copypasta.size()));
        if (args.length > 0) {
            message.delete();
            return "Too many arguments! Use `~help` to get usages.";
        } else if (args.length == 0) {
            message.delete();
            return StringUtils.abbreviate((":spaghetti: " + "**" + pasta.getTitle() + "**\n" + pasta.getSelftext()), 2000);
        }
    }

    // Something went wrong, display error message
    message.delete();
    return "An error occurred, please try again later.";
}
 
开发者ID:nbd9,项目名称:PastaBot,代码行数:34,代码来源:PastaCommand.java

示例4: onJokeCommand

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
@Command(aliases = {"joke", "prank"}, description = "Gets a random joke from /r/jokes.", usage = "joke")
public static String onJokeCommand(String[] args, IMessage message) throws OAuthException, RateLimitException, DiscordException, MissingPermissionsException {
    Listing<Submission> jokes = null;
    RedditClient redditClient;
    try {
        redditClient = Reddit.getRedditClient();
        if (!redditClient.isAuthenticated()) {
            Reddit.authReddit();
        }
        FluentRedditClient fluent = new FluentRedditClient(redditClient);
        jokes = fluent.subreddit("jokes").fetch();
    }   catch (NetworkException | NullPointerException e) {
        Reddit.authReddit();
        onJokeCommand(args, message);
    }

    Random random = new Random();
    System.out.println("Telling a bad joke.");

    if (jokes != null) {
        Submission joke = jokes.get(random.nextInt(jokes.size()));
        if (args.length > 0) {
            message.delete();
            return "Too many arguments! Use `~help` to get usages.";
        } else if (args.length == 0) {
            message.delete();
            return StringUtils.abbreviate((":rofl: " + "**" + joke.getTitle() + "**\n" + joke.getSelftext()), 2000);
        }
    }

    // Something went wrong, display error message.
    message.delete();
    return "An error occurred, please try again";
}
 
开发者ID:nbd9,项目名称:PastaBot,代码行数:35,代码来源:JokeCommand.java

示例5: executeCommand

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
@Override
public void executeCommand(Message msg) {
	EmbedBuilder em = new EmbedBuilder();
	String contents = Util.getCommandContents(msg);
	if(contents.isEmpty()) {
		MessageUtils.sendIncorrectCommandUsage(msg, this);
		return;
	}
	if(RedditEventListener.getObserver(contents, msg.getGuild()) != null) {
		if(RedditEventListener.getObserver(contents, msg.getGuild()).getDiscoChannel().equals(msg.getTextChannel())) {
			em.setTitle("Error",  null)
			.setColor(Color.RED)
			.setDescription("The subreddit /r/**" + contents + "** is already feeding to this channel");
			msg.getChannel().sendMessage(em.build()).queue();
			return;
		} else {
			// Remove previous channel as they are changing it
			RedditEventListener.removeRedditFeed(contents, msg.getGuild());
		}
	}
	try {
		RedditEventListener.redditClient.getSubreddit(contents);
	} catch(NetworkException | IllegalArgumentException e) {
		em.setTitle("Error", null)
		.setColor(Color.RED)
		.setDescription("The subreddit /r/**" + contents + "** does not exist");
		msg.getChannel().sendMessage(em.build()).queue();
		return;
	}
	RedditFeed instance = new RedditFeed(msg);
	ProceduralListener.getInstance().addListener(msg, instance);
	instance.sendMessage(getSteps()[super.getCurrentStep()]);
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:34,代码来源:RedditFeed.java

示例6: update

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
public static void update() {
	try {
		SubredditPaginator allNew = new SubredditPaginator(redditClient);
		allNew.setLimit(42);
		allNew.setSorting(Sorting.NEW);
		allNew.setSubreddit("all");
		Listing<Submission> posts = allNew.next();
		postSearch: {
			for (Submission post : posts) {
				for (String cutoff : cutoffIds) {
					if (post.getId().equals(cutoff)) {
						break postSearch;
					}
				}
				if (redditFeed.containsKey(post.getSubredditName().toLowerCase())) {
					if (redditFeed.get(post.getSubredditName().toLowerCase()).isEmpty()) {
						redditFeed.remove(post.getSubredditName().toLowerCase());
						saveFeed();
						continue;
					}
					redditFeed.get(post.getSubredditName().toLowerCase()).removeIf(observer -> !observer.trigger(post));
				}
			}
		}
		cutoffIds.clear();
		for (int i = 0; i < BUFFER_SIZE; i++) {
			cutoffIds.add(posts.get(i).getId());
		}
	} catch(NetworkException e) {
		try {
			reAuthenticate();
			update();
		} catch (NetworkException e1) {
			e1.printStackTrace();
		}
	}
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:38,代码来源:RedditEventListener.java

示例7: executeCommand

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
@Override
public void executeCommand(IMessage msg) {
	EmbedBuilder em = new EmbedBuilder();
	String contents = Util.getCommandContents(msg);
	if(contents.isEmpty()) {
		em = MessageUtils.commandErrorMessage(msg, "reddit", "subreddit",
				"**subreddit** - Subreddit to register your feed to.",
				"If you want to list all your feed subscriptions, do " + Util.getPrefixForGuildId(msg.getGuild().getID()) + "listreddit");
		MessageUtils.sendMessage(msg.getChannel(), em.build());
		return;
	}
	if(RedditEventListener.getObserver(contents, msg.getGuild()) != null) {
		if(RedditEventListener.getObserver(contents, msg.getGuild()).getDiscoChannel().equals(msg.getChannel())) {
			em.withColor(Color.RED).withTitle("Error").withDesc("The subreddit /r/**" + contents + "** is already feeding to this channel");
			MessageUtils.sendMessage(msg.getChannel(), em.build());
			return;
		} else {
			// Remove previous channel as they are changing it
			RedditEventListener.removeRedditFeed(contents, msg.getGuild());
		}
	}
	try {
		RedditEventListener.redditClient.getSubreddit(contents);
	} catch(NetworkException | IllegalArgumentException e) {
		em.withColor(Color.RED).withTitle("Error").withDesc("The subreddit /r/**" + contents + "** does not exist");
		MessageUtils.sendMessage(msg.getChannel(), em.build());
		return;
	}
	RedditFeed instance = new RedditFeed(msg);
	ProceduralListener.getInstance().addListener(msg, instance);
	instance.sendMessage(getSteps()[super.getCurrentStep()]);
}
 
开发者ID:paul-io,项目名称:momo-discord-old,代码行数:33,代码来源:RedditFeed.java

示例8: update

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
public static void update() {
	try {
		SubredditPaginator allNew = new SubredditPaginator(redditClient);
		allNew.setLimit(100);
		allNew.setSorting(Sorting.NEW);
		allNew.setSubreddit("all");
		Listing<Submission> posts = allNew.next();
		postSearch: {
			for(Submission post : posts) {
				for(String cutoff : cutoffIds) {
					if(post.getId().equals(cutoff))
						break postSearch;
				}
				if(redditFeed.containsKey(post.getSubredditName().toLowerCase())) {
					if(redditFeed.get(post.getSubredditName().toLowerCase()).isEmpty()) {
						redditFeed.remove(post.getSubredditName().toLowerCase());
						saveFeed();
						continue;
					}
					redditFeed.get(post.getSubredditName().toLowerCase()).removeIf(observer -> !observer.trigger(post));
				}
			}
		}
		cutoffIds.clear();
		for(int i = 0; i < BUFFER_SIZE; i++) {
			cutoffIds.add(posts.get(i).getId());
		}
	} catch(NetworkException e) {
		try {
			reAuthenticate();
			update();
		} catch (NetworkException e1) {
			e1.printStackTrace();
		}
	}
}
 
开发者ID:paul-io,项目名称:momo-discord-old,代码行数:37,代码来源:RedditEventListener.java

示例9: submitLink

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
public void submitLink(String subredditName, URL url, String title) throws ApiException, MalformedURLException {
    try {
        fluent.subreddit(subredditName).submit(url, title);
    }catch(NetworkException ae){
        logger.error(ae.getMessage(), ae);
        init();
        fluent.subreddit(subredditName).submit(url, title);
    }
}
 
开发者ID:vitalijzad,项目名称:java-rss-for-reddit,代码行数:10,代码来源:RedditSubmitter.java

示例10: submitLinkInternal

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
private void submitLinkInternal(String subredditName, URL url, String title, String flair) throws NetworkException, ApiException {
    Submission submission = fluent.subreddit(subredditName).submit(url, title);

    if(StringUtils.isNotBlank(flair)) {
        submitFlair(subredditName, submission, flair);
    }
}
 
开发者ID:vitalijzad,项目名称:java-rss-for-reddit,代码行数:8,代码来源:RedditSubmitter.java

示例11: authenticate

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
public AuthHelper authenticate() throws NetworkException, OAuthException{
	AuthHelper helper = new AuthHelper();
	UserAgent myUserAgent = UserAgent.of("desktop", "YouTubeBot", "0.1", "-YouTubeBot-");
	RedditClient redditClient = new RedditClient(myUserAgent);
	Credentials credentials = Credentials.script("-YouTubeBot-", "Ash3win#", "WnBQphrJ2jWY5A", "bJmaYXBDHUNfPGRpSEUPHOtLrIk");
	OAuthData authData = redditClient.getOAuthHelper().easyAuth(credentials);
	redditClient.authenticate(authData);
	helper.setCredentials(credentials);
	helper.setRedditClient(redditClient);
	return(helper);
}
 
开发者ID:ashwinswaroop,项目名称:YouTubeBot,代码行数:12,代码来源:Authenticator.java

示例12: getSubmission

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
public JsonNode getSubmission(SubmissionRequest request) throws NetworkException {
    Map<String, String> args = new HashMap<>();
    if (request.getDepth() != null) args.put("depth", Integer.toString(request.getDepth()));
    if (request.getContext() != null) {
        args.put("context", Integer.toString(request.getContext()));
    }
    if (request.getLimit() != null) args.put("limit", Integer.toString(request.getLimit()));
    if (request.getFocus() != null && !JrawUtils.isFullname(request.getFocus())) {
        args.put("comment", request.getFocus());
    }

    CommentSort sort = request.getSort();
    if (sort == null)
    // Reddit sorts by confidence by default
    {
        sort = CommentSort.CONFIDENCE;
    }
    args.put("sort", sort.name().toLowerCase(Locale.ENGLISH));

    try {

        RestResponse response = Authentication.reddit.execute(Authentication.reddit.request()
                .path(String.format("/comments/%s", request.getId()))
                .query(args)
                .build());
        return response.getJson();
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:ccrama,项目名称:Slide,代码行数:31,代码来源:CommentCacheAsync.java

示例13: authenticate

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
private static OAuthData authenticate() throws NetworkException, OAuthException {
	return redditClient.getOAuthHelper().easyAuth(credentials);
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:4,代码来源:RedditEventListener.java

示例14: pagesFor

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
public List<List<Submission>> pagesFor(String subreddit, Sorting sorting) {
    SubredditPaginator paginator = new SubredditPaginator(client(), subreddit);

    if (sorting != null) {
        paginator.setSorting(sorting);
    }

    paginator.setLimit(20);
    Listing<Submission> listing;

    try {
        listing = paginator.next();
    } catch (NetworkException ex) {
        if (ex.getResponse().getStatusCode() != 404) {
            sendToOwner("Was unable to make a request to reddit due to a NetworkException: " + ex.getMessage());
        }

        return new ArrayList<>();
    }

    // list of pages with 5 entries
    List<List<Submission>> paginated = new ArrayList<>();

    for (int page = 0; page < PAGES; page++) {
        List<Submission> submissions = new ArrayList<>(5);

        for (int index = 0; index < 5; index++) {
            int i = (page * 5) + index;

            if (i >= listing.size()) {
                break;
            }

            submissions.add(listing.get(i));
        }

        paginated.add(submissions);
    }

    return paginated;
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:42,代码来源:ReddigramBot.java

示例15: main

import net.dean.jraw.http.NetworkException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, NetworkException, ApiException, InterruptedException {
	in=new BufferedReader(new InputStreamReader(System.in));
	Thread t = new Thread(new YouTubeBot());
       t.start();
       String link;
       String pageSource;
       String youtubeLink;
       Submission sub;
       ArrayList<String> pageSources = new ArrayList<String>();
       ArrayList<String> oldPageSources = new ArrayList<String>();
       ArrayList<Submission> oldSubmissions = new ArrayList<Submission>();
       AuthHelper helper = new AuthHelper();
	Parser P = new Parser();
	Downloader D = new Downloader();
	Scanner S = new Scanner();
	Authenticator A = new Authenticator();
	Uploader U = new Uploader();
	Commenter C = new Commenter();
	helper = A.authenticate();
	Timer timer = new Timer();
	long refreshTime = 350000;
	timer.schedule(new Refresher(helper), refreshTime);
	System.out.println("OK1");
	while(true){
		pageSources = S.scanReddit(helper, pageSources);
		Iterator<String> pageSourcesIterator = pageSources.iterator();
		Iterator<Submission> submissionsIterator = Scanner.submissionList.iterator();
		if(!pageSources.isEmpty()){
			System.out.println("OK3");
			while(pageSourcesIterator.hasNext() && submissionsIterator.hasNext()){
				System.out.println("OK4");
				pageSource = pageSourcesIterator.next();
				sub = submissionsIterator.next();
				if(!oldPageSources.contains(pageSource)){
					oldPageSources.add(pageSource);
					link = P.parseSource(pageSource);
					D.downloadVideo(link);
					youtubeLink=U.upload(sub.getTitle(), sub.getUrl(), link);
					if(!oldSubmissions.contains(sub)){
						oldSubmissions.add(sub);
						C.comment(helper, sub, youtubeLink);	
					}
				}
			}
		}
	}
}
 
开发者ID:ashwinswaroop,项目名称:YouTubeBot,代码行数:48,代码来源:YouTubeBot.java


注:本文中的net.dean.jraw.http.NetworkException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。