private StorageItem storeSpecsIndex(SpecsIndexZippedFile file, InputStream content) throws Exception { ByteArrayOutputStream gzipped = new ByteArrayOutputStream(); try (OutputStream out = new GZIPOutputStream(gzipped)) { IOUtil.copy(content, out); } ContentLocator cl = new PreparedContentLocator(new ByteArrayInputStream(gzipped.toByteArray()), "application/x-gzip", gzipped.size()); DefaultStorageFileItem item = new DefaultStorageFileItem(repository, new ResourceStoreRequest(file.storagePath()), true, true, cl); repository.storeItem(false, item); return item; }
new DefaultStorageFileItem( repository, request, true /* canRead */, true /* canWrite */, contentLocator ); result.setLength( length ); result.setModified( lastModified ); result.setCreated( result.getModified() ); result.setRemoteUrl( itemUrl ); result.getItemContext().setParentContext( request.getRequestContext() );
public static void storeItem(final Repository repository, final ResourceStoreRequest request, final InputStream in, final String mimeType, final Map<String, String> userAttributes) throws Exception { final DefaultStorageFileItem fItem = new DefaultStorageFileItem(repository, request, true, true, new PreparedContentLocator(in, mimeType, ContentLocator.UNKNOWN_LENGTH)); if (userAttributes != null) { fItem.getRepositoryItemAttributes().putAll(userAttributes); } repository.storeItem(false, fItem); }
@Override public String getContentGeneratorId() { if ( isContentGenerated() ) { return getRepositoryItemAttributes().get( ContentGenerator.CONTENT_GENERATOR_ID ); } else { return null; } }
private void importFile(final File baseDir, final String relPath) throws StorageException, UnsupportedStorageOperationException, IllegalOperationException { final File source = new File(baseDir, relPath); final ResourceStoreRequest request = new ResourceStoreRequest(relPath); final DefaultStorageFileItem file = new DefaultStorageFileItem(this, request, source.canRead(), source.canWrite(), new FileContentLocator( source, getMimeSupport().guessMimeTypeFromPath(source.getName()))); file.setModified(source.lastModified()); file.setCreated(source.lastModified()); storeItem(false, file); }
@Deprecated protected AbstractStorageItem createStorageItem( ResourceStoreRequest request, byte[] bytes ) { ContentLocator content = new ByteArrayContentLocator( bytes, getMimeUtil().getMimeType( request.getRequestPath() ) ); DefaultStorageFileItem result = new DefaultStorageFileItem( this, request, true /* isReadable */, false /* isWritable */, content ); result.setLength( bytes.length ); return result; }
new DefaultStorageFileItem( repository, request, target.canRead(), target.canWrite(), new FileContentLocator( target, getMimeSupport().guessMimeTypeFromPath( repository.getMimeRulesSource(), target.getAbsolutePath() ) ) ); repository.getAttributesHandler().fetchAttributes( file ); file.setModified( target.lastModified() ); file.setCreated( target.lastModified() ); file.setLength( target.length() ); result = file;
@Override public void retrieve(SpecsIndexFile specs) { log.debug("retrieve :: {}", specs); SpecsIndexZippedFile source = specs.zippedSpecsIndexFile(); try { StorageFileItem item = (StorageFileItem) repository.retrieveDirectItem(new ResourceStoreRequest(source.storagePath())); DefaultStorageFileItem unzippedItem = new DefaultStorageFileItem(repository, new ResourceStoreRequest(specs.storagePath()), true, false, gunzipContentLocator(item)); unzippedItem.setModified(item.getModified()); specs.set(unzippedItem); } catch (ItemNotFoundException e) { specs.markAsNotExists(); } catch (IOException | IllegalOperationException e) { specs.setException(e); } }
private void createVirtualYumConfigFile(final MavenRepository repository) { DefaultStorageFileItem file = new DefaultStorageFileItem( repository, new ResourceStoreRequest(YumConfigContentGenerator.configFilePath(repository.getId())), true, false, new StringContentLocator(YumConfigContentGenerator.ID) ); file.setContentGeneratorId(YumConfigContentGenerator.ID); try { repository.storeItem(false, file); } catch (Exception e) { LOG.warn("Could not install yum.repo file '{}' due to {}/{}", file, e.getClass().getName(), e.getMessage()); } }
new DefaultStorageFileItem( this, to, true, true, new PreparedContentLocator( ( (StorageFileItem) item ).getInputStream(), ( (StorageFileItem) item ).getMimeType() ) ); target.getItemContext().putAll( item.getItemContext() );
@Override public void setLength( long length ) { getRepositoryItemAttributes().setLength( length ); }
protected void storeIndexItem(Repository repository, File file, IndexingContext context) { String path = PUBLISHING_PATH_PREFIX + "/" + file.getName(); try { ResourceStoreRequest request = new ResourceStoreRequest(path); DefaultStorageFileItem fItem = new DefaultStorageFileItem(repository, request, true, true, new FileContentLocator(file, mimeSupport.guessMimeTypeFromPath(repository.getMimeRulesSource(), file.getAbsolutePath()))); if (context.getTimestamp() == null) { fItem.setModified(0); fItem.setCreated(0); } else { fItem.setModified(context.getTimestamp().getTime()); fItem.setCreated(context.getTimestamp().getTime()); } if (repository instanceof MavenRepository) { // this is maven repo, so use the checksumming facility ((MavenRepository) repository).storeItemWithChecksums(false, fItem); } else { // simply store it repository.storeItem(false, fItem); } } catch (Exception e) { log.error("Cannot store index file " + path, e); } }
new DefaultStorageFileItem( this, request, true, false, contentLocator ); result.setLength( content.length ); result.setCreated( mdItem.getCreated() ); result.setModified( System.currentTimeMillis() ); return result;
new DefaultStorageFileItem(repository, new ResourceStoreRequest(ARCHETYPE_PATH), true, false, new StringContentLocator(ArchetypeContentGenerator.ID)); file.setContentGeneratorId(ArchetypeContentGenerator.ID); repository.storeItem(false, file);
@Override public long getLength() { return getRepositoryItemAttributes().getLength(); }
private void putStorageItem( final String path, final ContentLocator contentLocator ) throws IOException { try { ResourceStoreRequest req = new ResourceStoreRequest( path ); DefaultStorageFileItem mdFile = new DefaultStorageFileItem( repository, req, true, true, contentLocator ); repository.storeItem( false, mdFile ); // TODO: why? storeItem() already does this!!! repository.removeFromNotFoundCache( req ); } catch ( Exception e ) { throw new IOException( e ); } }
new DefaultStorageFileItem( repository, request, CAN_READ, CAN_WRITE, new PreparedContentLocator( is, mimeType ) ); httpItem.setLength( httpResponse.getEntity().getContentLength() ); httpItem.setRemoteUrl( remoteURL.toString() ); httpItem.setModified( makeDateFromHeader( httpResponse.getFirstHeader( "last-modified" ) ) ); httpItem.setCreated( httpItem.getModified() ); httpItem.getItemContext().putAll( request.getRequestContext() );
new DefaultStorageFileItem( repository, path, true, true, new PreparedContentLocator( fis, mimeUtil.getMimeType( file ) ) ); fItem.setModified( 0 ); fItem.setCreated( 0 ); fItem.setModified( context.getTimestamp().getTime() ); fItem.setCreated( context.getTimestamp().getTime() );
public void storeItem( ResourceStoreRequest request, InputStream is, Map<String, String> userAttributes ) throws UnsupportedStorageOperationException, IllegalOperationException, StorageException, AccessDeniedException { if ( !checkConditions( request, getResultingActionOnWrite( request ) ) ) { throw new AccessDeniedException( request, "Operation does not fills needed requirements!" ); } DefaultStorageFileItem fItem = new DefaultStorageFileItem( this, request, true, true, new PreparedContentLocator( is, getMimeSupport().guessMimeTypeFromPath( getMimeRulesSource(), request.getRequestPath() ) ) ); if ( userAttributes != null ) { fItem.getRepositoryItemAttributes().putAll( userAttributes ); } storeItem( false, fItem ); }
@Override public boolean isContentGenerated() { return getRepositoryItemAttributes().containsKey( ContentGenerator.CONTENT_GENERATOR_ID ); }