List of usage examples for org.apache.commons.net.nntp ArticlePointer ArticlePointer
ArticlePointer
From source file:com.almarsoft.GroundhogReader.lib.NNTPExtended.java
public long[] getGroupArticles(String group, long fromArticle, int limit) throws IOException { Vector<Long> list; long firstToGet, firstArticle, lastArticle; NewsgroupInfo groupInfo = new NewsgroupInfo(); if (!selectNewsgroup(group, groupInfo)) return null; firstArticle = groupInfo.getFirstArticle(); lastArticle = groupInfo.getLastArticle(); if (firstArticle == 0 && lastArticle == 0) return new long[0]; // First sync with this group; see the comment below if (fromArticle == -1) firstToGet = firstArticle;/*w w w. j a v a 2 s . c o m*/ else { if (fromArticle > lastArticle) { // No new articles return new long[0]; } else { firstToGet = fromArticle; } } // Now select the first article and start looping until limit or last article reached ArticlePointer art = new ArticlePointer(); list = new Vector<Long>(limit); // FIRST CONNECTION TO THE GROUP // If this is the first connection we only want the last "limit" articles from the group, // so we ask for the last message and go backwards until we have "limit" articles or // the first one. if (fromArticle == -1) { if (!selectArticle(lastArticle, art)) return new long[0]; for (int i = 0; i < limit; i++) { list.insertElementAt((long) art.articleNumber, 0); if (art.articleNumber == firstToGet) break; if (!selectPreviousArticle(art)) break; } } // NON-FIRST CONNECTION TO THE GROUP // For normal non-first connection we start with the last article we got on the previous session and advance from that // until limit or last article reached else { if (!selectArticle(firstToGet, art)) return new long[0]; for (int i = 0; i <= limit; i++) { list.add((long) art.articleNumber); if (art.articleNumber == lastArticle) break; if (!selectNextArticle(art)) break; } } int listSize = list.size(); long[] articleNumbers = new long[listSize]; for (int i = 0; i < listSize; i++) { articleNumbers[i] = list.get(i); } return articleNumbers; }