org.alfresco.repo.content.filestore.SpoofedTextContentReader Java Examples
The following examples show how to use
org.alfresco.repo.content.filestore.SpoofedTextContentReader.
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: CachingContentStore.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * <p> * This store handles the {@link FileContentStore#SPOOF_PROTOCOL} so that underlying stores do not need * to implement anything <a href="https://issues.alfresco.com/jira/browse/ACE-4516">related to spoofing</a>. */ @Override public ContentReader getReader(String contentUrl) { // Handle the spoofed URL if (contentUrl.startsWith(FileContentStore.SPOOF_PROTOCOL)) { return new SpoofedTextContentReader(contentUrl); } // Use pool of locks - which one is determined by a hash of the URL. // This will stop the content from being read/cached multiple times from the backing store // when it should only be read once - cached versions should be returned after that. ReadLock readLock = readWriteLock(contentUrl).readLock(); readLock.lock(); try { if (cache.contains(contentUrl)) { return cache.getReader(contentUrl); } } catch(CacheMissException e) { // Fall through to cacheAndRead(url); } finally { readLock.unlock(); } return cacheAndRead(contentUrl); }
Example #2
Source File: CachingContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void spoofedGetReader() { cachingStore = new CachingContentStore(backingStore, cache, true); String url = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 0L, 1024L); ContentReader reader = cachingStore.getReader(url); assertTrue(reader.exists()); assertEquals(1024, reader.getSize()); verify(backingStore, never()).getReader(anyString()); }
Example #3
Source File: CachingContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void spoofedDelete() { cachingStore = new CachingContentStore(backingStore, cache, true); String url = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 0L, 1024L); boolean deleted = cachingStore.delete(url); assertFalse(deleted); verify(backingStore, never()).delete(anyString()); }
Example #4
Source File: CachingContentStoreTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void spoofedExists() { cachingStore = new CachingContentStore(backingStore, cache, true); String url = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 0L, 1024L); boolean exists = cachingStore.exists(url); assertTrue(exists); verify(backingStore, never()).exists(anyString()); }
Example #5
Source File: RemoteFileFolderLoaderTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Load 15 files; 1K size; 1 document sample; force binary storage */ @SuppressWarnings("unchecked") public void testLoad_15_16bytes() throws Exception { JSONObject body = new JSONObject(); body.put(FileFolderLoaderPost.KEY_FOLDER_PATH, loadHomePath); body.put(FileFolderLoaderPost.KEY_MIN_FILE_SIZE, 16L); body.put(FileFolderLoaderPost.KEY_MAX_FILE_SIZE, 16L); body.put(FileFolderLoaderPost.KEY_MAX_UNIQUE_DOCUMENTS, 1L); body.put(FileFolderLoaderPost.KEY_FORCE_BINARY_STORAGE, Boolean.TRUE); Response response = null; try { AuthenticationUtil.pushAuthentication(); AuthenticationUtil.setFullyAuthenticatedUser("maggi"); response = sendRequest( new PostRequest(URL, body.toString(), "application/json"), Status.STATUS_OK, "maggi"); } finally { AuthenticationUtil.popAuthentication(); } assertEquals("{\"count\":100}", response.getContentAsString()); // Check file(s) assertEquals(100, nodeService.countChildAssocs(loadHomeNodeRef, true)); // Consistent binary text String contentUrlCheck = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 0L, 16L); ContentReader readerCheck = new SpoofedTextContentReader(contentUrlCheck); String textCheck = readerCheck.getContentString(); // Size should be default List<FileInfo> fileInfos = fileFolderService.list(loadHomeNodeRef); for (FileInfo fileInfo : fileInfos) { NodeRef fileNodeRef = fileInfo.getNodeRef(); ContentReader reader = fileFolderService.getReader(fileNodeRef); // Expect storage in store assertTrue(reader.getContentUrl().startsWith(FileContentStore.STORE_PROTOCOL)); // Check text String text = reader.getContentString(); assertEquals("Text not the same.", textCheck, text); } }