public class FileDataChannel extends Object implements IDataChannel
OP_GET_POSITION, OP_GET_SIZE, OP_READ, OP_SET_POSITION, OP_SET_SIZE, OP_TRANSFER_FROM, OP_TRANSFER_TO, OP_WRITE| Constructor and Description |
|---|
FileDataChannel(FileChannel channel) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Solicita o fechamento do canal.
|
FileChannel |
getChannel()
Retorna o FileChannel encapsulado
|
long |
getPosition()
Obtém a posição atual do canal.
|
long |
getSize()
Obtém a quantidade de bytes no canal a partir da posição inicial.
|
boolean |
isOpen()
Verifica se o canal está aberto.
|
int |
read(ByteBuffer target)
Lê uma sequência de bytes do arquivo.
|
int |
read(ByteBuffer target,
long position)
Lê uma sequência de bytes do arquivo.
|
long |
remaining()
Retorna a quantidade de bytes no canal a partir da posição atual.
|
void |
setPosition(long position)
Define a nova posição do arquivo.
|
void |
setSize(long size)
Define a quantidade de bytes para o canal.
|
long |
skip(long bytes)
Metodo que pula/ignora uma quantidade de bytes a partir da posicao atual.
|
short |
supportedOperations()
Retornas os metodos/operações suportados pela implementação do canal de
dados.
|
long |
transferFrom(ReadableByteChannel source,
long position,
long count)
Transfere os dados de um fluxo de entrada para o arquivo.
|
long |
transferTo(long position,
long count,
WritableByteChannel output)
Transfere os dados do arquivo para um fluxo de saída.
|
int |
write(ByteBuffer source)
Escreve uma sequência de bytes no arquivo.
|
int |
write(ByteBuffer source,
long position)
Escreve uma sequência de bytes no arquivo.
|
public FileDataChannel(FileChannel channel)
channel - public short supportedOperations()
supportedOperations in interface IDataChannelpublic boolean isOpen()
isOpen in interface ChannelisOpen in interface IDataChanneltrue caso o canal esteja aberto, ou false, caso
contrário.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface Channelclose in interface IDataChannelIOException - Caso ocorra alguma falha no procedimento.public long remaining()
throws IOException,
DataChannelException
IDataChannelremaining in interface IDataChannelIOException - Caso ocorra alguma falha no procedimento.DataChannelException - Caso ocorra alguma situação excepcional no canal.public long skip(long bytes)
throws IOException,
DataChannelException
IDataChannelskip in interface IDataChannelbytes - quantidade de bytes a serem pulados. Quantidade de bytes a serem
pulados deve ser maior ou igual a zero.IOException - Caso ocorra alguma falha no procedimento.DataChannelException - Caso ocorra alguma situação excepcional no canal.public long getSize()
throws IOException
UnsupportedOperationException.getSize in interface IDataChannelIOException - Caso ocorra alguma falha no procedimento.public void setSize(long size)
throws IOException
UnsupportedOperationException.setSize in interface IDataChannelsize - O novo tamanho.IOException - Caso ocorra alguma falha no procedimento.public long getPosition()
throws IOException
UnsupportedOperationException.getPosition in interface IDataChannelIOException - Caso ocorra alguma falha no procedimento.public void setPosition(long position)
throws IOException
UnsupportedOperationException.setPosition in interface IDataChannelposition - A nova posição.IOException - Caso ocorra alguma falha no procedimento.public int read(ByteBuffer target) throws IOException
UnsupportedOperationException.read in interface IDataChanneltarget - O buffer.IOException - Caso ocorra alguma falha I/O no procedimento.public int read(ByteBuffer target, long position) throws IOException
UnsupportedOperationException.read in interface IDataChanneltarget - O buffer.position - A posição do arquivo a partir da qual a leitura vai ser iniciada.IOException - Caso ocorra alguma falha no procedimento.public int write(ByteBuffer source) throws IOException
UnsupportedOperationException.write in interface IDataChannelsource - O buffer.IOException - Caso ocorra alguma falha no procedimento.public int write(ByteBuffer source, long position) throws IOException
UnsupportedOperationException.write in interface IDataChannelsource - O buffer.position - A posição do arquivo a partir da qual a escrita vai ser iniciada.IOException - Caso ocorra alguma falha no procedimento.public long transferTo(long position,
long count,
WritableByteChannel output)
throws IOException
UnsupportedOperationException.transferTo in interface IDataChannelposition - A posição inicial a partir daqual o arquivo será lido.count - A quantidade de bytes que serão transferidos.output - O fluxo de saída que receberá os dados do arquivo.IOException - Caso ocorra alguma falha no procedimento.public long transferFrom(ReadableByteChannel source, long position, long count) throws IOException
UnsupportedOperationException.transferFrom in interface IDataChannelsource - O fluxo de entrada.position - A posição inicial a partir daqual o arquivo será escrito.count - A quantidade de bytes que serão transferidos.IOException - Caso ocorra alguma falha no procedimento.public FileChannel getChannel()
Copyright © 2019 Tecgraf/PUC-Rio. All rights reserved.