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


Java SeekableByteChannel.position方法代碼示例

本文整理匯總了Java中java.nio.channels.SeekableByteChannel.position方法的典型用法代碼示例。如果您正苦於以下問題:Java SeekableByteChannel.position方法的具體用法?Java SeekableByteChannel.position怎麽用?Java SeekableByteChannel.position使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.channels.SeekableByteChannel的用法示例。


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

示例1: LineReader

import java.nio.channels.SeekableByteChannel; //導入方法依賴的package包/類
public LineReader(final ReadableByteChannel channel)
throws IOException {
    buf = ByteBuffer.allocate(BUF_SIZE);
    buf.flip();

    boolean removeLine = false;
    // If we are not at the beginning of a line, we should ignore the current line.
    if (channel instanceof SeekableByteChannel) {
        SeekableByteChannel seekChannel = (SeekableByteChannel) channel;
        if (seekChannel.position() > 0) {
            // Start from one character back and read till we find a new line.
            seekChannel.position(seekChannel.position() - 1);
            removeLine = true;
        }
        nextLineStart = seekChannel.position();
    }

    this.channel = channel;
    if (removeLine) {
        nextLineStart += readNextLine(new ByteArrayOutputStream());
    }
}
 
開發者ID:obradovicluka,項目名稱:dataflow-playground,代碼行數:23,代碼來源:CsvWithHeaderFileSource.java

示例2: xorFiles

import java.nio.channels.SeekableByteChannel; //導入方法依賴的package包/類
public static void xorFiles(SeekableByteChannel inputA, SeekableByteChannel inputB,
                            SeekableByteChannel outputChannel, long limit) throws IOException {
	ByteBuffer aBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
	ByteBuffer bBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
	ByteBuffer outBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE);

	do {
		if (inputA.position() == inputA.size()) inputA.position(0);
		if (inputB.position() == inputB.size()) inputB.position(0);

		inputA.read(aBuffer);
		inputB.read(bBuffer);
		aBuffer.flip();
		bBuffer.flip();
		int cap = min(aBuffer.remaining(), bBuffer.remaining(), outBuffer.remaining());
		for (int i = 0; i < cap; i += 8) {
			long a = aBuffer.getLong();
			long b = bBuffer.getLong();
			outBuffer.putLong(a ^ b);
		}
		aBuffer.compact();
		bBuffer.compact();

		outBuffer.flip();
		long bytesRequired = limit - outputChannel.size();
		if (outBuffer.limit() > bytesRequired) outBuffer.limit((int) bytesRequired);
		outputChannel.write(outBuffer);
		outBuffer.compact();
	} while (outputChannel.size() < limit);
}
 
開發者ID:zeobviouslyfakeacc,項目名稱:ModLoaderInstaller,代碼行數:31,代碼來源:FileUtils.java

示例3: openStream

import java.nio.channels.SeekableByteChannel; //導入方法依賴的package包/類
@Override
public InputStream openStream() throws IOException {
    parseDatHeader();
    SeekableByteChannel channel = Files.newByteChannel(datFile);
    channel.position(Math.abs(position) + headerLen);
    return new CountingStream(Channels.newInputStream(channel), dataLen);
}
 
開發者ID:nla,項目名稱:httrack2warc,代碼行數:8,代碼來源:NdxCache.java

示例4: main

import java.nio.channels.SeekableByteChannel; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        AuthTimeWithHash a1 = new AuthTimeWithHash(client, server, time(0), 0,
                "1111111111111111");
        AuthTimeWithHash a2 = new AuthTimeWithHash(client, server, time(0), 0,
                "2222222222222222");
        KerberosTime now = new KerberosTime(time(0)*1000L);

        // When all new styles, must exact match
        ReplayCache cache = ReplayCache.getInstance("dfl:./c1");
        cache.checkAndStore(now, a1);
        cache.checkAndStore(now, a2);

        // When only old style in cache, partial match
        cache = ReplayCache.getInstance("dfl:./c2");
        cache.checkAndStore(now, a1);
        // A small surgery to remove the new style from the cache file
        SeekableByteChannel ch = Files.newByteChannel(Paths.get("c2"),
                StandardOpenOption.WRITE,
                StandardOpenOption.READ);
        ch.position(6);
        ch.write(ByteBuffer.wrap(a1.encode(false)));
        ch.truncate(ch.position());
        ch.close();
        try {
            cache.checkAndStore(now, a2);
            throw new Exception();
        } catch (KrbException ke) {
            // Correct
            System.out.println(ke);
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:33,代碼來源:ReplayCachePrecise.java

示例5: main

import java.nio.channels.SeekableByteChannel; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        AuthTimeWithHash a1 = new AuthTimeWithHash(client, server, time(0), 0,
                "HASH", "1111111111111111");
        AuthTimeWithHash a2 = new AuthTimeWithHash(client, server, time(0), 0,
                "HASH", "2222222222222222");
        KerberosTime now = new KerberosTime(time(0)*1000L);

        // When all new styles, must exact match
        ReplayCache cache = ReplayCache.getInstance("dfl:./c1");
        cache.checkAndStore(now, a1);
        cache.checkAndStore(now, a2);

        // When only old style in cache, partial match
        cache = ReplayCache.getInstance("dfl:./c2");
        cache.checkAndStore(now, a1);
        // A small surgery to remove the new style from the cache file
        SeekableByteChannel ch = Files.newByteChannel(Paths.get("c2"),
                StandardOpenOption.WRITE,
                StandardOpenOption.READ);
        ch.position(6);
        ch.write(ByteBuffer.wrap(a1.encode(false)));
        ch.truncate(ch.position());
        ch.close();
        try {
            cache.checkAndStore(now, a2);
            throw new Exception();
        } catch (KrbException ke) {
            // Correct
            System.out.println(ke);
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:ReplayCachePrecise.java


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