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


Java CharBuffer.rewind方法代碼示例

本文整理匯總了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);
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:JavaFlyTokensTest.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:CslTestBase.java

示例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();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:JavaLexerPerformanceTest.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:TokenDumpCheck.java

示例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();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:StockName.java

示例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");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:46,代碼來源:CompletionContextTest.java

示例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);
    }

}
 
開發者ID:cpitman,項目名稱:webhook-step,代碼行數:42,代碼來源:WebhookRootAction.java


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