org.alfresco.util.TempFileProvider Java Examples
The following examples show how to use
org.alfresco.util.TempFileProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractMetadataExtracterTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
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()); } }
Example #2
Source File: RepositoryExporterComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public FileExportHandle exportSystem(String packageName) { // create a temporary file to hold the system info export File systemTempDir = TempFileProvider.getSystemTempDir(); File tempFile = TempFileProvider.createTempFile("repoExpSystemInfo", ".xml", systemTempDir); try { OutputStream outputStream = new FileOutputStream(tempFile); systemExporterImporter.exportSystem(outputStream); } catch(FileNotFoundException e) { tempFile.delete(); throw new ExporterException("Failed to create temporary file for holding export of system info"); } // return handle onto temp file FileExportHandle handle = new FileExportHandle(); handle.storeRef = null; handle.packageName = packageName; handle.mimeType = MimetypeMap.MIMETYPE_XML; handle.exportFile = tempFile; return handle; }
Example #3
Source File: JodConverterMetadataExtracterWorker.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable { String sourceMimetype = reader.getMimetype(); if (logger.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Extracting metadata content from ") .append(sourceMimetype); logger.debug(msg.toString()); } // create temporary files to convert from and to File tempFile = TempFileProvider.createTempFile(this.getClass() .getSimpleName() + "-", "." + mimetypeService.getExtension(sourceMimetype)); // download the content from the source reader reader.getContent(tempFile); ResultsCallback callback = new ResultsCallback(); jodc.getOfficeManager().execute(new ExtractMetadataOfficeTask(tempFile, callback)); return callback.getResults(); }
Example #4
Source File: CreateDownloadArchiveAction.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private void createDownload(final NodeRef actionedUponNodeRef, ExporterCrawlerParameters crawlerParameters, SizeEstimator estimator) { // perform the actual export final File tempFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX); final ZipDownloadExporter handler = new ZipDownloadExporter(tempFile, checkOutCheckInService, nodeService, transactionHelper, updateService, downloadStorage, actionedUponNodeRef, estimator.getSize(), estimator.getFileCount()); try { exporterService.exportView(handler, crawlerParameters, null); archiveCreationComplete(actionedUponNodeRef, tempFile, handler); } catch (DownloadCancelledException ex) { downloadCancelled(actionedUponNodeRef, handler); } finally { tempFile.delete(); } }
Example #5
Source File: ContentServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Service initialise */ public void init() { // Set up a temporary store this.tempStore = new FileContentStore(this.applicationContext, TempFileProvider.getTempDir().getAbsolutePath()); // Bind on update properties behaviour this.policyComponent.bindClassBehaviour( NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME, this, new JavaBehaviour(this, "onUpdateProperties")); // Register on content update policy this.onContentUpdateDelegate = this.policyComponent.registerClassPolicy(OnContentUpdatePolicy.class); this.onContentPropertyUpdateDelegate = this.policyComponent.registerClassPolicy(OnContentPropertyUpdatePolicy.class); this.onContentReadDelegate = this.policyComponent.registerClassPolicy(OnContentReadPolicy.class); }
Example #6
Source File: RepositoryExporterComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public FileExportHandle exportSystem(String packageName) { // create a temporary file to hold the system info export File tempFile = TempFileProvider.createTempFile("repoExpSystemInfo", ".xml"); try { OutputStream outputStream = new FileOutputStream(tempFile); systemExporterImporter.exportSystem(outputStream); } catch(FileNotFoundException e) { tempFile.delete(); throw new ExporterException("Failed to create temporary file for holding export of system info"); } // return handle onto temp file FileExportHandle handle = new FileExportHandle(); handle.storeRef = null; handle.packageName = packageName; handle.mimeType = MimetypeMap.MIMETYPE_XML; handle.exportFile = tempFile; return handle; }
Example #7
Source File: SchemaBootstrap.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Dumps the DB schema to temporary file(s), named similarly to: * <pre> * Alfresco-schema-DialectName-whenDumped-dbPrefix-23498732.xml * </pre> * Where the digits serve to create a unique temp file name. If whenDumped is empty or null, * then the output is similar to: * <pre> * Alfresco-schema-DialectName-dbPrefix-23498732.xml * </pre> * If dbPrefixes is null, then the default list is used (see {@link MultiFileDumper#DEFAULT_PREFIXES}) * The dump files' paths are logged at info level. * * @param whenDumped String * @param dbPrefixes Array of database object prefixes to filter by, e.g. "alf_" * @return List of output files. */ private List<File> dumpSchema(String whenDumped, String[] dbPrefixes) { // Build a string to use as the file name template, // e.g. "Alfresco-schema-MySQLDialect-pre-upgrade-{0}-" StringBuilder sb = new StringBuilder(64); sb.append("Alfresco-schema-"). append(dialect.getClass().getSimpleName()); if (whenDumped != null && whenDumped.length() > 0) { sb.append("-"); sb.append(whenDumped); } sb.append("-{0}-"); File outputDir = TempFileProvider.getTempDir(); String fileNameTemplate = sb.toString(); return dumpSchema(outputDir, fileNameTemplate, dbPrefixes); }
Example #8
Source File: ModuleManagementToolTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private String extractToDir(String extension, String location) { File tmpDir = TempFileProvider.getTempDir(); try { TFile zipFile = new TFile(this.getClass().getClassLoader().getResource(location).getPath()); TFile outDir = new TFile(tmpDir.getAbsolutePath()+"/moduleManagementToolTestDir"+System.currentTimeMillis()); outDir.mkdir(); zipFile.cp_rp(outDir); TVFS.umount(zipFile); return outDir.getPath(); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #9
Source File: ExporterComponentTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * @param nodeRef nodeRef * @return File * @throws FileNotFoundException * @throws IOException */ private File exportContent(NodeRef nodeRef) throws FileNotFoundException, IOException { TestProgress testProgress = new TestProgress(); Location location = new Location(nodeRef); ExporterCrawlerParameters parameters = new ExporterCrawlerParameters(); parameters.setExportFrom(location); File acpFile = TempFileProvider.createTempFile("category-export-test", ACPExportPackageHandler.ACP_EXTENSION); System.out.println("Exporting to file: " + acpFile.getAbsolutePath()); File dataFile = new File("test-data-file"); File contentDir = new File("test-content-dir"); OutputStream fos = new FileOutputStream(acpFile); ACPExportPackageHandler acpHandler = new ACPExportPackageHandler(fos, dataFile, contentDir, null); acpHandler.setNodeService(nodeService); acpHandler.setExportAsFolders(true); exporterService.exportView(acpHandler, parameters, testProgress); fos.close(); return acpFile; }
Example #10
Source File: BufferedResponseTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test that the output stream creates a temp file to cache its content when file size was bigger than its memory threshold ( 5 > 4 MB ) * MNT-19833 */ @Test public void testOutputStream() throws IOException { File bufferTempDirectory = TempFileProvider.getTempDir(TEMP_DIRECTORY_NAME); TempOutputStreamFactory streamFactory = new TempOutputStreamFactory(bufferTempDirectory, MEMORY_THRESHOLD, MAX_CONTENT_SIZE, false,true); BufferedResponse response = new BufferedResponse(null, 0, streamFactory); long countBefore = countFilesInDirectoryWithPrefix(bufferTempDirectory, FILE_PREFIX ); copyFileToOutputStream(response); long countAfter = countFilesInDirectoryWithPrefix(bufferTempDirectory, FILE_PREFIX); response.getOutputStream().close(); Assert.assertEquals(countBefore + 1, countAfter); }
Example #11
Source File: AbstractContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Writes the supplied text out to a temporary file, and opens * a content reader onto it. */ protected static ContentReader buildContentReader(String text, Charset encoding) throws IOException { File tmpFile = TempFileProvider.createTempFile("AlfrescoTest_", ".txt"); FileOutputStream out = new FileOutputStream(tmpFile); OutputStreamWriter wout = new OutputStreamWriter(out, encoding); wout.write(text); wout.close(); out.close(); ContentReader reader = new FileContentReader(tmpFile); reader.setEncoding(encoding.displayName()); reader.setMimetype("text/plain"); return reader; }
Example #12
Source File: SerializeTests.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testInvokeMultiPartEntity() throws IOException { ResourceWithMetadata entityResource = locator.locateEntityResource(api,"multiparttest", HttpMethod.POST); assertNotNull(entityResource); MultiPartResourceAction.Create<?> resource = (MultiPartResourceAction.Create<?>) entityResource.getResource(); File file = TempFileProvider.createTempFile("ParamsExtractorTests-", ".txt"); PrintWriter writer = new PrintWriter(file); writer.println("Multipart Mock test2."); writer.close(); MultiPartRequest reqBody = MultiPartBuilder.create() .setFileData(new FileData(file.getName(), file, MimetypeMap.MIMETYPE_TEXT_PLAIN)) .build(); MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST", ""); mockRequest.setContent(reqBody.getBody()); mockRequest.setContentType(reqBody.getContentType()); String out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api,null, NOT_USED, resource.create(new FormData(mockRequest), NOT_USED, callBack))); assertTrue("There must be json output", StringUtils.startsWith(out, "{\"entry\":")); }
Example #13
Source File: OpenOfficeContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test what is up with HTML to PDF */ public void testHtmlToPdf() throws Exception { if (!isOpenOfficeWorkerAvailable()) { // no connection System.err.println("ooWorker not available - skipping testHtmlToPdf !!"); return; } File htmlSourceFile = loadQuickTestFile("html"); File pdfTargetFile = TempFileProvider.createTempFile(getName() + "-target-", ".pdf"); ContentReader reader = new FileContentReader(htmlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_HTML); ContentWriter writer = new FileContentWriter(pdfTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_PDF); transformer.transform(reader, writer); }
Example #14
Source File: OpenOfficeContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * ALF-219. Transforamtion from .html to .pdf for empty file. * @throws Exception */ // The test was never run and fails on remote transformer public void ignoreTestEmptyHtmlToEmptyPdf() throws Exception { if (!isOpenOfficeWorkerAvailable()) { // no connection System.err.println("ooWorker not available - skipping testEmptyHtmlToEmptyPdf !!"); return; } URL url = this.getClass().getClassLoader().getResource("misc/empty.html"); assertNotNull("URL was unexpectedly null", url); File htmlSourceFile = new File(url.getFile()); assertTrue("Test file does not exist.", htmlSourceFile.exists()); File pdfTargetFile = TempFileProvider.createTempFile(getName() + "-target-", ".pdf"); ContentReader reader = new FileContentReader(htmlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_HTML); ContentWriter writer = new FileContentWriter(pdfTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_PDF); transformer.transform(reader, writer); }
Example #15
Source File: MailContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid msg file to text */ public void testMsgToText() throws Exception { File msgSourceFile = loadQuickTestFile("msg"); File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-1", ".txt"); ContentReader reader = new FileContentReader(msgSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); assertTrue(reader2.getContentString().contains(QUICK_CONTENT)); }
Example #16
Source File: MailContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid unicode msg file to text */ public void testUnicodeMsgToText() throws Exception { File msgSourceFile = loadQuickTestFile("unicode.msg"); File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-2", ".txt"); ContentReader reader = new FileContentReader(msgSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); assertTrue(reader2.getContentString().contains(QUICK_CONTENT)); }
Example #17
Source File: MailContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a chinese non-unicode msg file to * text */ public void testNonUnicodeChineseMsgToText() throws Exception { File msgSourceFile = loadQuickTestFile("chinese.msg"); File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-2", ".txt"); ContentReader reader = new FileContentReader(msgSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); // Check the quick text String text = reader2.getContentString(); assertTrue(text.contains(QUICK_CONTENT)); // Now check the non quick parts came out ok assertTrue(text.contains("(\u5f35\u6bd3\u502b)")); assertTrue(text.contains("\u683c\u5f0f\u6e2c\u8a66 )")); }
Example #18
Source File: MediaWikiContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void testMediaWikiToHTML() throws Exception { File input = TempFileProvider.createTempFile("mediaWikiTest", ".mw"); FileOutputStream fos = new FileOutputStream(input); fos.write(WIKI_TEXT.getBytes()); fos.close(); File output = TempFileProvider.createTempFile("mediaWikiTest", ".htm"); ContentReader contentReader = new FileContentReader(input); contentReader.setMimetype(MimetypeMap.MIMETYPE_TEXT_MEDIAWIKI); contentReader.setEncoding("UTF-8"); ContentWriter contentWriter = new FileContentWriter(output); contentWriter.setMimetype(MimetypeMap.MIMETYPE_HTML); contentWriter.setEncoding("UTF-8"); transformer.transform(contentReader, contentWriter); String line = null; BufferedReader reader = new BufferedReader(new FileReader(output)); while ((line = reader.readLine()) != null) { System.out.println(line); } }
Example #19
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid eml with an attachment to text; attachment should be ignored */ public void testRFC822WithAttachmentToText() throws Exception { File emlSourceFile = loadQuickTestFile("attachment.eml"); File txtTargetFile = TempFileProvider.createTempFile("test3", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); String contentStr = reader2.getContentString(); assertTrue(contentStr.contains(QUICK_EML_WITH_ATTACHMENT_CONTENT)); assertTrue(!contentStr.contains(QUICK_EML_ATTACHMENT_CONTENT)); }
Example #20
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid eml with minetype multipart/alternative to text */ public void testRFC822AlternativeToText() throws Exception { File emlSourceFile = loadQuickTestFile("alternative.eml"); File txtTargetFile = TempFileProvider.createTempFile("test4", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); String contentStr = reader2.getContentString(); assertTrue(contentStr.contains(QUICK_EML_ALTERNATIVE_CONTENT)); }
Example #21
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid eml with nested mimetype multipart/alternative to text */ public void testRFC822NestedAlternativeToText() throws Exception { File emlSourceFile = loadQuickTestFile("nested.alternative.eml"); File txtTargetFile = TempFileProvider.createTempFile("test5", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); String contentStr = reader2.getContentString(); assertTrue(contentStr.contains(QUICK_EML_NESTED_ALTERNATIVE_CONTENT)); }
Example #22
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid eml with a html part containing html special characters to text */ public void testHtmlSpecialCharsToText() throws Exception { File emlSourceFile = loadQuickTestFile("htmlChars.eml"); File txtTargetFile = TempFileProvider.createTempFile("test6", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); String contentStr = reader2.getContentString(); assertTrue(!contentStr.contains(HTML_SPACE_SPECIAL_CHAR)); }
Example #23
Source File: RoutingContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void before() throws Exception { File tempDir = TempFileProvider.getTempDir(); // Create a subdirectory for A File storeADir = new File(tempDir, "A"); storeA = new FileContentStore(ctx, storeADir); // Create a subdirectory for B File storeBDir = new File(tempDir, "B"); storeB = new FileContentStore(ctx, storeBDir); // Create a subdirectory for C File storeCDir = new File(tempDir, "C"); storeC = new DumbReadOnlyFileStore(new FileContentStore(ctx, storeCDir)); // No subdirectory for D storeD = new SupportsNoUrlFormatStore(); // Create the routing store routingStore = new RandomRoutingContentStore(storeA, storeB, storeC, storeD); }
Example #24
Source File: AbstractBaseApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected Document createTextFile(String parentId, String fileName, String textContent, String encoding, Map<String, String> props, int expectedStatus) throws IOException, Exception { if (props == null) { props = Collections.EMPTY_MAP; } ByteArrayInputStream inputStream = new ByteArrayInputStream(textContent.getBytes()); File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt"); MultiPartBuilder.MultiPartRequest reqBody = MultiPartBuilder.create() .setFileData(new MultiPartBuilder.FileData(fileName, txtFile)) .setProperties(props) .build(); HttpResponse response = post(getNodeChildrenUrl(parentId), reqBody.getBody(), null, reqBody.getContentType(), expectedStatus); if (response.getJsonResponse().get("error") != null) { return null; } return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); }
Example #25
Source File: ContentCacheImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void canVisitOldestDirsFirst() { File cacheRoot = new File(TempFileProvider.getTempDir(), GUID.generate()); cacheRoot.deleteOnExit(); contentCache.setCacheRoot(cacheRoot); File f1 = tempfile(createDirs("2000/3/30/17/45/31"), "files-are-unsorted.bin"); File f2 = tempfile(createDirs("2000/3/4/17/45/31"), "another-file.bin"); File f3 = tempfile(createDirs("2010/12/24/23/59/58"), "a-second-before.bin"); File f4 = tempfile(createDirs("2010/12/24/23/59/59"), "last-one.bin"); File f5 = tempfile(createDirs("2000/1/7/2/7/12"), "first-one.bin"); // Check that directories and files are visited in correct order FileHandler handler = Mockito.mock(FileHandler.class); contentCache.processFiles(handler); InOrder inOrder = Mockito.inOrder(handler); inOrder.verify(handler).handle(f5); inOrder.verify(handler).handle(f2); inOrder.verify(handler).handle(f1); inOrder.verify(handler).handle(f3); inOrder.verify(handler).handle(f4); }
Example #26
Source File: ReadOnlyFileContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void before() throws Exception { // create a store that uses a subdirectory of the temp directory File tempDir = TempFileProvider.getTempDir(); store = new FileContentStore(ctx, tempDir.getAbsolutePath() + File.separatorChar + getName()); // Put some content into it ContentWriter writer = store.getWriter(new ContentContext(null, null)); writer.putContent("Content for getExistingContentUrl"); this.contentUrl = writer.getContentUrl(); // disallow random access store.setReadOnly(true); }
Example #27
Source File: AbstractMetadataExtracterTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Ensures that the temp locations are cleaned out before the tests start */ @Override public void setUp() throws Exception { // Grab the context, which will normally have been // cached by the ApplicationContextHelper ctx = MiscContextTestSuite.getMinimalContext(); this.mimetypeMap = (MimetypeMap) ctx.getBean("mimetypeService"); this.dictionaryService = (DictionaryService) ctx.getBean("dictionaryService"); // perform a little cleaning up long now = System.currentTimeMillis(); TempFileProvider.TempFileCleanerJob.removeFiles(now); TimeZone tz = TimeZone.getTimeZone("GMT"); TimeZone.setDefault(tz); // Joda time has already grabbed the JVM zone so re-set it here DateTimeZone.setDefault(DateTimeZone.forTimeZone(tz)); }
Example #28
Source File: AbstractContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Ensures that the temp locations are cleaned out before the tests start */ @Override protected void setUp() throws Exception { // Grab a suitably configured context ctx = MiscContextTestSuite.getMinimalContext(); // Grab other useful beans serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); mimetypeService = serviceRegistry.getMimetypeService(); transformerDebug = (TransformerDebug) ctx.getBean("transformerDebug"); transformerConfig = (TransformerConfig) ctx.getBean("transformerConfig"); // perform a little cleaning up long now = System.currentTimeMillis(); TempFileProvider.TempFileCleanerJob.removeFiles(now); }
Example #29
Source File: StringExtractingContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generate a large file and then transform it using the text extractor. * We are not creating super-large file (1GB) in order to test the transform * as it takes too long to create the file in the first place. Rather, * this test can be used during profiling to ensure that memory is not * being consumed. */ public void testLargeFileStreaming() throws Exception { File sourceFile = TempFileProvider.createTempFile(getName(), ".txt"); int chars = 1000000; // a million characters should do the trick Random random = new Random(); Writer charWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(sourceFile))); for (int i = 0; i < chars; i++) { char next = (char)(random.nextDouble() * 93D + 32D); charWriter.write(next); } charWriter.close(); // get a reader and a writer ContentReader reader = new FileContentReader(sourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); File outputFile = TempFileProvider.createTempFile(getName(), ".txt"); ContentWriter writer = new FileContentWriter(outputFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); // transform transformer.transform(reader, writer); // delete files sourceFile.delete(); outputFile.delete(); }
Example #30
Source File: CachingContentStoreSpringTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void before() throws Exception { File tempDir = TempFileProvider.getTempDir(); backingStore = new FileContentStore(ctx, tempDir.getAbsolutePath() + File.separatorChar + getName()); cache = new ContentCacheImpl(); cache.setCacheRoot(TempFileProvider.getLongLifeTempDir("cached_content_test")); cache.setMemoryStore(createMemoryStore()); store = new CachingContentStore(backingStore, cache, false); }