本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentWriter.getReader方法的典型用法代码示例。如果您正苦于以下问题:Java ContentWriter.getReader方法的具体用法?Java ContentWriter.getReader怎么用?Java ContentWriter.getReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentWriter
的用法示例。
在下文中一共展示了ContentWriter.getReader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCopyCommand
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void testCopyCommand() throws Exception
{
String content = "<A><B></B></A>";
// create the source
File sourceFile = TempFileProvider.createTempFile(getName() + "_", ".txt");
ContentWriter tempWriter = new FileContentWriter(sourceFile);
tempWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
tempWriter.putContent(content);
ContentReader reader = tempWriter.getReader();
// create the target
File targetFile = TempFileProvider.createTempFile(getName() + "_", ".xml");
ContentWriter writer = new FileContentWriter(targetFile);
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
// do the transformation
transformer.transform(reader, writer); // no options on the copy
// make sure that the content was copied over
ContentReader checkReader = writer.getReader();
String checkContent = checkReader.getContentString();
assertEquals("Content not copied", content, checkContent);
}
示例2: testCsvOutput
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void testCsvOutput() throws Exception
{
File sourceFile = AbstractContentTransformerTest.loadQuickTestFile("xls");
ContentReader sourceReader = new FileContentReader(sourceFile);
File targetFile = TempFileProvider.createTempFile(
getClass().getSimpleName() + "_" + getName() + "_xls_",
".csv");
ContentWriter targetWriter = new FileContentWriter(targetFile);
sourceReader.setMimetype(MimetypeMap.MIMETYPE_EXCEL);
targetWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_CSV);
transformer.transform(sourceReader, targetWriter);
ContentReader targetReader = targetWriter.getReader();
String checkContent = targetReader.getContentString();
additionalContentCheck(
MimetypeMap.MIMETYPE_EXCEL,
MimetypeMap.MIMETYPE_TEXT_CSV,
checkContent
);
}
示例3: writeToCacheWithExistingReader
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Test
public void writeToCacheWithExistingReader()
{
ContentWriter oldWriter = store.getWriter(ContentContext.NULL_CONTEXT);
oldWriter.putContent("Old content for " + getClass().getSimpleName());
ContentReader existingReader = oldWriter.getReader();
// Write through the caching content store - cache during the process.
final String proposedUrl = FileContentStore.createNewFileStoreUrl();
ContentWriter writer = store.getWriter(new ContentContext(existingReader, proposedUrl));
final String content = makeContent();
writer.putContent(content);
assertEquals("Writer should have correct URL", proposedUrl, writer.getContentUrl());
assertFalse("Old and new writers must have different URLs",
oldWriter.getContentUrl().equals(writer.getContentUrl()));
ContentReader reader = store.getReader(writer.getContentUrl());
assertEquals("Reader and writer should have same URLs", writer.getContentUrl(), reader.getContentUrl());
assertEquals("Reader should get correct content", content, reader.getContentString());
}
示例4: testStringTruncation
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Test
public void testStringTruncation() throws Exception
{
String content = "1234567890";
ContentWriter writer = getWriter();
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8"); // shorter format i.t.o. bytes used
// write the content
writer.putContent(content);
// get a reader - get it in a larger format i.t.o. bytes
ContentReader reader = writer.getReader();
String checkContent = reader.getContentString(5);
assertEquals("Truncated strings don't match", "12345", checkContent);
}
示例5: testReadAndWriteStreamByPull
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Test
public void testReadAndWriteStreamByPull() throws Exception
{
ContentWriter writer = getWriter();
String content = "ABC";
// put the content using a stream
InputStream is = new ByteArrayInputStream(content.getBytes());
writer.putContent(is);
assertTrue("Stream close not detected", writer.isClosed());
// get the content using a stream
ByteArrayOutputStream os = new ByteArrayOutputStream(100);
ContentReader reader = writer.getReader();
reader.getContent(os);
byte[] bytes = os.toByteArray();
String check = new String(bytes);
assertEquals("Write out and read in using streams failed", content, check);
}
示例6: testReadAndWriteStreamByPush
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Test
public void testReadAndWriteStreamByPush() throws Exception
{
ContentWriter writer = getWriter();
String content = "Some Random Content";
// get the content output stream
OutputStream os = writer.getContentOutputStream();
os.write(content.getBytes());
assertFalse("Stream has not been closed", writer.isClosed());
// close the stream and check again
os.close();
assertTrue("Stream close not detected", writer.isClosed());
// pull the content from a stream
ContentReader reader = writer.getReader();
InputStream is = reader.getContentInputStream();
byte[] buffer = new byte[100];
int count = is.read(buffer);
assertEquals("No content read", content.length(), count);
is.close();
String check = new String(buffer, 0, count);
assertEquals("Write out of and read into files failed", content, check);
}
示例7: testZeroLengthFile
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void testZeroLengthFile() throws Exception
{
MetadataExtracter extractor = getExtracter();
File file = TempFileProvider.createTempFile(getName(), ".bin");
ContentWriter writer = new FileContentWriter(file);
writer.getContentOutputStream().close();
ContentReader reader = writer.getReader();
// Try the zero length file against all supported mimetypes.
// Note: Normally the reader would need to be fetched for each access, but we need to be sure
// that the content is not accessed on the reader AT ALL.
PropertyMap properties = new PropertyMap();
List<String> mimetypes = mimetypeMap.getMimetypes();
for (String mimetype : mimetypes)
{
if (!extractor.isSupported(mimetype))
{
// Not interested
continue;
}
reader.setMimetype(mimetype);
extractor.extract(reader, properties);
assertEquals("There should not be any new properties", 0, properties.size());
}
}
示例8: getSafeContentReader
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Checks the existing reader provided and replaces it with a reader onto some
* fake content if required. If the existing reader is invalid, an debug message
* will be logged under this classname category.
* <p>
* It is a convenience method that clients can use to cheaply get a reader that
* is valid, regardless of whether the initial reader is valid.
*
* @param existingReader a potentially invalid reader or null
* @param msgTemplate the template message that will used to format the final <i>fake</i> content
* @param args arguments to put into the <i>fake</i> content
* @return Returns a the existing reader or a new reader onto some generated text content
*/
public static ContentReader getSafeContentReader(ContentReader existingReader, String msgTemplate, Object ... args)
{
ContentReader reader = existingReader;
if (existingReader == null || !existingReader.exists())
{
// the content was never written to the node or the underlying content is missing
String fakeContent = MessageFormat.format(msgTemplate, args);
// log it
if (logger.isDebugEnabled())
{
logger.debug(fakeContent);
}
// fake the content
File tempFile = TempFileProvider.createTempFile("getSafeContentReader_", ".txt");
ContentWriter writer = new FileContentWriter(tempFile);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(fakeContent);
// grab the reader from the temp writer
reader = writer.getReader();
}
// done
if (logger.isDebugEnabled())
{
logger.debug("Created safe content reader: \n" +
" existing reader: " + existingReader + "\n" +
" safe reader: " + reader);
}
return reader;
}
示例9: transform
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
protected void transform(String sourceMimetype, String targetMimetype, TransformationOptions options) throws IOException
{
String[] quickFiles = getQuickFilenames(sourceMimetype);
for (String quickFile : quickFiles)
{
String sourceExtension = quickFile.substring(quickFile.lastIndexOf('.')+1);
String targetExtension = mimetypeService.getExtension(targetMimetype);
// is there a test file for this conversion?
File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile(quickFile);
if (sourceFile == null)
{
continue; // no test file available for that extension
}
ContentReader sourceReader = new FileContentReader(sourceFile);
// make a writer for the target file
File targetFile = TempFileProvider.createTempFile(
getClass().getSimpleName() + "_" + getName() + "_" + sourceExtension + "_",
"." + targetExtension);
ContentWriter targetWriter = new FileContentWriter(targetFile);
// do the transformation
sourceReader.setMimetype(sourceMimetype);
targetWriter.setMimetype(targetMimetype);
transformer.transform(sourceReader.getReader(), targetWriter, options);
ContentReader targetReader = targetWriter.getReader();
assertTrue(targetReader.getSize() > 0);
}
}
示例10: writeContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Writes some content using the mimetype and encoding specified.
*
* @param mimetype String
* @param encoding String
* @return Returns a reader onto the newly written content
*/
private ContentReader writeContent(String mimetype, String encoding)
{
ContentWriter writer = new FileContentWriter(getTempFile());
writer.setMimetype(mimetype);
writer.setEncoding(encoding);
// put content
writer.putContent(SOME_CONTENT);
// return a reader onto the new content
return writer.getReader();
}
示例11: testReaderImmutability
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Check that a reader is immutable, i.e. that a reader fetched before a
* write doesn't suddenly become aware of the content once it has been written.
*/
@Test
public void testReaderImmutability()
{
ContentWriter writer = getWriter();
ContentReader readerBeforeWrite = writer.getReader();
assertNotNull(readerBeforeWrite);
assertFalse(readerBeforeWrite.exists());
// Write some content
writer.putContent("Content for testReaderImmutability");
assertFalse("Reader's state changed after write", readerBeforeWrite.exists());
try
{
readerBeforeWrite.getContentString();
fail("Reader's state changed after write");
}
catch (ContentIOException e)
{
// Expected
}
// A new reader should work
ContentReader readerAfterWrite = writer.getReader();
assertTrue("New reader after write should be directed to new content", readerAfterWrite.exists());
}
示例12: testMimetypAndEncodingAndLocale
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Test
public void testMimetypAndEncodingAndLocale() throws Exception
{
ContentWriter writer = getWriter();
// set mimetype and encoding
writer.setMimetype("text/plain");
writer.setEncoding("UTF-16");
writer.setLocale(Locale.CHINESE);
// create a UTF-16 string
String content = "A little bit o' this and a little bit o' that";
byte[] bytesUtf16 = content.getBytes("UTF-16");
// write the bytes directly to the writer
OutputStream os = writer.getContentOutputStream();
os.write(bytesUtf16);
os.close();
// now get a reader from the writer
ContentReader reader = writer.getReader();
assertEquals("Writer -> Reader content URL mismatch", writer.getContentUrl(), reader.getContentUrl());
assertEquals("Writer -> Reader mimetype mismatch", writer.getMimetype(), reader.getMimetype());
assertEquals("Writer -> Reader encoding mismatch", writer.getEncoding(), reader.getEncoding());
assertEquals("Writer -> Reader locale mismatch", writer.getLocale(), reader.getLocale());
// now get the string directly from the reader
String contentCheck = reader.getContentString(); // internally it should have taken care of the encoding
assertEquals("Encoding and decoding of strings failed", content, contentCheck);
}
示例13: testWriteAndReadString
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* The simplest test. Write a string and read it again, checking that we receive the same values.
* If the resource accessed by {@link #getReader(String)} and {@link #getWriter()} is not the same, then
* values written and read won't be the same.
*/
@Test
public void testWriteAndReadString() throws Exception
{
ContentWriter writer = getWriter();
String content = "ABC";
writer.putContent(content);
assertTrue("Stream close not detected", writer.isClosed());
ContentReader reader = writer.getReader();
String check = reader.getContentString();
assertTrue("Read and write may not share same resource", check.length() > 0);
assertEquals("Write and read didn't work", content, check);
}
示例14: testReadAndWriteFile
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Test
public void testReadAndWriteFile() throws Exception
{
ContentWriter writer = getWriter();
File sourceFile = TempFileProvider.createTempFile("testReadAndWriteFile", ".txt");
sourceFile.deleteOnExit();
// dump some content into the temp file
String content = "ABC";
FileOutputStream os = new FileOutputStream(sourceFile);
os.write(content.getBytes());
os.flush();
os.close();
// put our temp file's content
writer.putContent(sourceFile);
assertTrue("Stream close not detected", writer.isClosed());
// create a sink temp file
File sinkFile = TempFileProvider.createTempFile("testReadAndWriteFile", ".txt");
sinkFile.deleteOnExit();
// get the content into our temp file
ContentReader reader = writer.getReader();
reader.getContent(sinkFile);
// read the sink file manually
FileInputStream is = new FileInputStream(sinkFile);
byte[] buffer = new byte[100];
int count = is.read(buffer);
assertEquals("No content read", 3, count);
is.close();
String check = new String(buffer, 0, count);
assertEquals("Write out of and read into files failed", content, check);
}
示例15: testRandomAccessRead
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的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();
}