本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentReader.getFileChannel方法的典型用法代码示例。如果您正苦于以下问题:Java ContentReader.getFileChannel方法的具体用法?Java ContentReader.getFileChannel怎么用?Java ContentReader.getFileChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentReader
的用法示例。
在下文中一共展示了ContentReader.getFileChannel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRandomAccessRead
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Tests random access reading
* <p>
* Only executes if the reader implements {@link RandomAccessContent}.
*/
@Test
public void testRandomAccessRead() throws Exception
{
ContentStore store = getStore();
String contentUrl = getExistingContentUrl();
if (contentUrl == null)
{
logger.warn("Store test testRandomAccessRead not possible on " + store.getClass().getName());
return;
}
// Get the reader
ContentReader reader = store.getReader(contentUrl);
assertNotNull("Reader should never be null", reader);
FileChannel fileChannel = reader.getFileChannel();
assertNotNull("No channel given", fileChannel);
// check that no other content access is allowed
try
{
reader.getReadableChannel();
fail("Second channel access allowed");
}
catch (RuntimeException e)
{
// expected
}
fileChannel.close();
}
示例2: testRandomAccessRead
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Tests random access reading
* <p>
* Only executes if the reader implements {@link RandomAccessContent}.
*/
@Test
public void testRandomAccessRead() throws Exception
{
ContentWriter writer = getWriter();
// put some content
String content = "ABC";
byte[] bytes = content.getBytes();
writer.putContent(content);
ContentReader reader = writer.getReader();
FileChannel fileChannel = reader.getFileChannel();
assertNotNull("No channel given", fileChannel);
// check that no other content access is allowed
try
{
reader.getReadableChannel();
fail("Second channel access allowed");
}
catch (RuntimeException e)
{
// expected
}
// read the content
ByteBuffer buffer = ByteBuffer.allocate(bytes.length);
int count = fileChannel.read(buffer);
assertEquals("Incorrect number of bytes read", bytes.length, count);
// transfer back to array
buffer.rewind();
buffer.get(bytes);
String checkContent = new String(bytes);
assertEquals("Content read failure", content, checkContent);
fileChannel.close();
}
示例3: doTest
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
private static void doTest(ApplicationContext ctx, String baseUrl, String contentUrl) throws Exception
{
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
TransactionService transactionService = serviceRegistry.getTransactionService();
AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
// Construct the store
HttpAlfrescoStore store = new HttpAlfrescoStore();
store.setTransactionService(transactionService);
store.setAuthenticationService(authenticationService);
store.setBaseHttpUrl(baseUrl);
// Now test
System.out.println(
" Retrieving reader for URL " + contentUrl);
ContentReader reader = store.getReader(contentUrl);
System.out.println(
" Retrieved reader for URL " + contentUrl);
// Check if the content exists
boolean exists = reader.exists();
if (!exists)
{
System.out.println(
" Content doesn't exist: " + contentUrl);
return;
}
else
{
System.out.println(
" Content exists: " + contentUrl);
}
// Get the content data
ContentData contentData = reader.getContentData();
System.out.println(
" Retrieved content data: " + contentData);
// Now get the content
ByteBuffer buffer = ByteBuffer.allocate((int)reader.getSize());
FileChannel channel = reader.getFileChannel();
try
{
int count = channel.read(buffer);
if (count != reader.getSize())
{
System.err.println("The number of bytes read was " + count + " but expected " + reader.getSize());
return;
}
}
finally
{
channel.close();
}
}