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


Java PositionedReadable類代碼示例

本文整理匯總了Java中org.apache.hadoop.fs.PositionedReadable的典型用法代碼示例。如果您正苦於以下問題:Java PositionedReadable類的具體用法?Java PositionedReadable怎麽用?Java PositionedReadable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: read

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
/** Positioned read. It is thread-safe */
@Override
public int read(long position, byte[] buffer, int offset, int length)
    throws IOException {
  checkStream();
  try {
    final int n = ((PositionedReadable) in).read(position, buffer, offset, 
        length);
    if (n > 0) {
      // This operation does not change the current offset of the file
      decrypt(position, buffer, offset, n);
    }
    
    return n;
  } catch (ClassCastException e) {
    throw new UnsupportedOperationException("This stream does not support " +
        "positioned read.");
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:20,代碼來源:CryptoInputStream.java

示例2: readFully

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
/** Positioned read fully. It is thread-safe */
@Override
public void readFully(long position, byte[] buffer, int offset, int length)
    throws IOException {
  checkStream();
  try {
    ((PositionedReadable) in).readFully(position, buffer, offset, length);
    if (length > 0) {
      // This operation does not change the current offset of the file
      decrypt(position, buffer, offset, length);
    }
  } catch (ClassCastException e) {
    throw new UnsupportedOperationException("This stream does not support " +
        "positioned readFully.");
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:17,代碼來源:CryptoInputStream.java

示例3: testOnMessageSuccessful

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
@Test
public void testOnMessageSuccessful() throws IOException {
  InputStream mis = mock(InputStream.class, withSettings().extraInterfaces(Seekable.class, PositionedReadable.class));
  doReturn(42).when(mis).read(any(byte[].class), anyInt(), anyInt());

  FSDataInputStream fdis = new FSDataInputStream(mis);
  Response response = getResponse(7L, 4096, fdis);

  InOrder inOrder = Mockito.inOrder(mis);

  inOrder.verify((Seekable) mis).seek(7);
  inOrder.verify(mis).read(any(byte[].class), anyInt(), anyInt());

  assertEquals(42, ((DFS.GetFileDataResponse) response.pBody).getRead());
  assertEquals(42, response.dBodies[0].readableBytes());
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:17,代碼來源:TestPDFSProtocol.java

示例4: testOnMessageEOF

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
@Test
public void testOnMessageEOF() throws IOException {
  InputStream mis = mock(InputStream.class, withSettings().extraInterfaces(Seekable.class, PositionedReadable.class));
  doReturn(-1).when(mis).read(any(byte[].class), anyInt(), anyInt());

  FSDataInputStream fdis = new FSDataInputStream(mis);
  Response response = getResponse(7L, 4096, fdis);

  InOrder inOrder = Mockito.inOrder(mis);

  inOrder.verify((Seekable) mis).seek(7);
  inOrder.verify(mis).read(any(byte[].class), anyInt(), anyInt());

  assertEquals(-1, ((DFS.GetFileDataResponse) response.pBody).getRead());
  assertEquals(0, response.dBodies.length);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:17,代碼來源:TestPDFSProtocol.java

示例5: in

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
/** Get input stream. */
private PositionedReadable in() throws IOException {
    synchronized (mux) {
        if (opened) {
            if (err != null)
                throw err;
        }
        else {
            opened = true;

            try {
                in = fs.open(path, bufSize);

                if (in == null)
                    throw new IOException("Failed to open input stream (file system returned null): " + path);
            }
            catch (IOException e) {
                err = e;

                throw err;
            }
        }

        return in;
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:27,代碼來源:HadoopIgfsSecondaryFileSystemPositionedReadable.java

示例6: getPos

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
/**
 * This method returns the current position in the stream.
 *
 * @return Current position in stream as a long
 */
@Override
public long getPos() throws IOException {
  if (!(in instanceof Seekable) || !(in instanceof PositionedReadable)){
    //This way of getting the current position will not work for file
    //size which can be fit in an int and hence can not be returned by
    //available method.
    return (this.maxAvailableData - this.in.available());
  }
  else{
    return ((Seekable)this.in).getPos();
  }

}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:19,代碼來源:CompressionInputStream.java

示例7: readAll

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
private int readAll(InputStream in, long pos, byte[] b, int off, int len) 
    throws IOException {
  int n = 0;
  int total = 0;
  while (n != -1) {
    total += n;
    if (total >= len) {
      break;
    }
    n = ((PositionedReadable) in).read(pos + total, b, off + total, 
        len - total);
  }
  
  return total;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:16,代碼來源:CryptoStreamsTestBase.java

示例8: readFullyCheck

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
private void readFullyCheck(InputStream in, int pos) throws Exception {
  byte[] result = new byte[dataLen - pos];
  ((PositionedReadable) in).readFully(pos, result);
  
  byte[] expectedData = new byte[dataLen - pos];
  System.arraycopy(data, pos, expectedData, 0, dataLen - pos);
  Assert.assertArrayEquals(result, expectedData);
  
  result = new byte[dataLen]; // Exceeds maximum length 
  try {
    ((PositionedReadable) in).readFully(pos, result);
    Assert.fail("Read fully exceeds maximum length should fail.");
  } catch (IOException e) {
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:16,代碼來源:CryptoStreamsTestBase.java

示例9: read

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
/**
 * Read bytes starting from the specified position. This requires rawStream is an instance of
 * {@link PositionedReadable}.
 */
public int read(long position, byte[] buffer, int offset, int length) throws IOException {
  if (!(rawStream instanceof PositionedReadable)) {
    throw new UnsupportedOperationException("positioned read is not supported by the internal stream");
  }
  throttle();
  int readLen = ((PositionedReadable) rawStream).read(position, buffer, offset, length);
  if (readLen != -1) {
    bytesRead += readLen;
  }
  return readLen;
}
 
開發者ID:HotelsDotCom,項目名稱:circus-train,代碼行數:16,代碼來源:ThrottledInputStream.java

示例10: read

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
/**
 * Read bytes starting from the specified position. This requires rawStream is
 * an instance of {@link PositionedReadable}.
 */
public int read(long position, byte[] buffer, int offset, int length)
    throws IOException {
  if (!(rawStream instanceof PositionedReadable)) {
    throw new UnsupportedOperationException(
        "positioned read is not supported by the internal stream");
  }
  throttle();
  int readLen = ((PositionedReadable) rawStream).read(position, buffer,
      offset, length);
  if (readLen != -1) {
    bytesRead += readLen;
  }
  return readLen;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:ThrottledInputStream.java

示例11: read

import org.apache.hadoop.fs.PositionedReadable; //導入依賴的package包/類
/**
 * Read bytes starting from the specified position. This requires rawStream is
 * an instance of {@link PositionedReadable}.
 * @param position
 * @param buffer
 * @param offset
 * @param length
 * @return the number of bytes read
 */
public int read(long position, byte[] buffer, int offset, int length)
    throws IOException {
  if (!(rawStream instanceof PositionedReadable)) {
    throw new UnsupportedOperationException(
      "positioned read is not supported by the internal stream");
  }
  throttle();
  int readLen = ((PositionedReadable) rawStream).read(position, buffer,
    offset, length);
  if (readLen != -1) {
    bytesRead += readLen;
  }
  return readLen;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:24,代碼來源:ThrottledInputStream.java


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