本文整理匯總了Java中java.nio.CharBuffer.rewind方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.rewind方法的具體用法?Java CharBuffer.rewind怎麽用?Java CharBuffer.rewind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.CharBuffer
的用法示例。
在下文中一共展示了CharBuffer.rewind方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import java.nio.CharBuffer; //導入方法依賴的package包/類
public void test() throws Exception {
File testJComponentFile = new File(getDataDir() + "/testfiles/JComponent.java.txt");
FileReader r = new FileReader(testJComponentFile);
int fileLen = (int)testJComponentFile.length();
CharBuffer cb = CharBuffer.allocate(fileLen);
r.read(cb);
cb.rewind();
String text = cb.toString();
TokenHierarchy<?> hi = TokenHierarchy.create(text, JavaTokenId.language());
TokenSequence<?> ts = hi.tokenSequence();
System.err.println("Flyweight tokens: " + LexerTestUtilities.flyweightTokenCount(ts)
+ "\nTotal tokens: " + ts.tokenCount()
+ "\nFlyweight text length: " + LexerTestUtilities.flyweightTextLength(ts)
+ "\nTotal text length: " + fileLen
+ "\nDistribution: " + LexerTestUtilities.flyweightDistribution(ts)
);
assertEquals(LexerTestUtilities.flyweightTokenCount(ts), 13786);
assertEquals(LexerTestUtilities.flyweightTextLength(ts), 21710);
assertEquals(ts.tokenCount(), 21379);
}
示例2: readFile
import java.nio.CharBuffer; //導入方法依賴的package包/類
public static String readFile(File f) throws IOException {
FileReader r = new FileReader(f);
int fileLen = (int)f.length();
CharBuffer cb = CharBuffer.allocate(fileLen);
r.read(cb);
cb.rewind();
return cb.toString();
}
示例3: readJComponentFile
import java.nio.CharBuffer; //導入方法依賴的package包/類
private String readJComponentFile() throws Exception {
File testJComponentFile = new File(getDataDir() + "/testfiles/JComponent.java.txt");
FileReader r = new FileReader(testJComponentFile);
try {
int fileLen = (int)testJComponentFile.length();
CharBuffer cb = CharBuffer.allocate(fileLen);
r.read(cb);
cb.rewind();
return cb.toString();
} finally {
r.close();
}
}
示例4: readFile
import java.nio.CharBuffer; //導入方法依賴的package包/類
private static String readFile(NbTestCase test, File f) throws Exception {
FileReader r = new FileReader(f);
int fileLen = (int)f.length();
CharBuffer cb = CharBuffer.allocate(fileLen);
r.read(cb);
cb.rewind();
return cb.toString();
}
示例5: test
import java.nio.CharBuffer; //導入方法依賴的package包/類
private static void test(CharBuffer cb, String exp) {
cb.limit(cb.position());
cb.rewind();
if (!cb.toString().equals(exp))
throw new RuntimeException("expect: '" + exp + "'; got: '"
+ cb.toString() + "'");
cb.clear();
}
示例6: prepareData
import java.nio.CharBuffer; //導入方法依賴的package包/類
private void prepareData(String tokenName, String fname) throws Exception {
File dataDir = getDataDir();
File f = new File(dataDir, CompletionContextTest.class.getPackage().getName().replaceAll("\\.", "/") +
"/" + fname);
InputStream stream = new FileInputStream(f);
InputStreamReader rd = new InputStreamReader(stream, "UTF-8");
StringBuffer sb = new StringBuffer();
CharBuffer cb = CharBuffer.allocate(10000);
while (rd.read(cb) != -1) {
cb.flip();
sb.append(cb.toString());
cb.rewind();
}
rd.close();
String text = sb.toString();
// strip all occurrences of markers:
String pristine = text.replaceAll(MARKER, "");
Pattern p = Pattern.compile(MARKER);
Matcher m = p.matcher(text);
TestSuite ts = new TestSuite(CompletionContextTest.class.getName());
while (m.find()) {
String val = m.group(1);
String name = m.group(2);
if (!name.equals(tokenName)) {
continue;
}
int offset = m.start();
String cleanBefore = text.substring(0, offset).replaceAll(MARKER, "");
this.text = pristine;
this.state = val;
this.stateVal = CompletionContext.Type.valueOf(val);
this.offset = cleanBefore.length();
return;
}
throw new IllegalArgumentException("Token " + tokenName + " not found in the template");
}
示例7: doDynamic
import java.nio.CharBuffer; //導入方法依賴的package包/類
public void doDynamic(StaplerRequest request, StaplerResponse response) {
String token = request.getOriginalRestOfPath().substring(1); //Strip leading slash
CharBuffer dest = CharBuffer.allocate(request.getContentLength());
try {
BufferedReader reader = request.getReader();
while (reader.read(dest) > 0) {
//Intentionally blank
}
} catch (IOException e) {
response.setStatus(400);
return;
}
dest.rewind();
String content = dest.toString();
Logger.getLogger(WebhookRootAction.class.getName())
.info("Webhook called with " + token);
WaitForWebhookExecution exec;
synchronized (webhooks) {
exec = webhooks.remove(token);
if (exec == null) {
//pipeline has not yet waited on webhook, add an entry to track
//that it was already triggered
alreadyPosted.put(token, content);
}
}
if (exec != null) {
exec.onTriggered(content);
response.setHeader("Result", "WebhookTriggered");
response.setStatus(200);
} else {
response.setStatus(202);
}
}