public OutputStream getOutputStream() throws IOException { return new FileOutputStream( getFile() ); }
@Override public InputStream getContent() throws IOException { return getInputStream(); }
private static StorageFileItem compressMetadataItem(final Repository repository, final String path, final StorageFileItem metadataXml) throws IOException { final Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); // this is a special one: once cached (hence consumed), temp file gets deleted final FileContentLocator fileContentLocator = new FileContentLocator("application/java-archive"); try (OutputStream buffer = fileContentLocator.getOutputStream(); ZipOutputStream out = new ZipOutputStream(buffer); InputStream in = metadataXml.getInputStream()) { out.putNextEntry(new JarEntry(metadataXml.getName())); IOUtils.copy(in, out); } final DefaultStorageFileItem result = new DefaultStorageFileItem( repository, new ResourceStoreRequest(path), true /* isReadable */, false /* isWritable */, fileContentLocator ); return result; }
final FileContentLocator fileContentLocator = new FileContentLocator("text/xml"); try { try (OutputStream buffer = fileContentLocator.getOutputStream();) { final MXSerializer mx = new MXSerializer(); mx.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " "); fileContentLocator.delete();
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); }
protected static StorageFileItem createMetadataItem(final Repository repository, final String path, final Xpp3Dom metadata, final String hack, final RequestContext context) throws IOException { // this is a special one: once cached (hence consumed), temp file get's deleted final FileContentLocator fileContentLocator = new FileContentLocator("text/xml"); try (OutputStream buffer = fileContentLocator.getOutputStream()) { final MXSerializer mx = new MXSerializer(); mx.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " "); mx.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n"); final String encoding = "UTF-8"; mx.setOutput(buffer, encoding); mx.startDocument(encoding, null); if (hack != null) { mx.processingInstruction(hack); } metadata.writeToSerializer(null, mx); mx.flush(); } final ResourceStoreRequest request = new ResourceStoreRequest(path); request.getRequestContext().setParentContext(context); final DefaultStorageFileItem result = new DefaultStorageFileItem(repository, request, true /* isReadable */, false /* isWritable */, fileContentLocator); return result; }
private void storeItemFromFile(final String path, final File file, final P2ProxyRepository repository) throws LocalStorageException, UnsupportedStorageOperationException { final ContentLocator content = new FileContentLocator(file, "text/xml"); final DefaultStorageFileItem storageItem = new DefaultStorageFileItem(repository, new ResourceStoreRequest(path), true /* isReadable */, false /* isWritable */, content); repository.getLocalStorage().storeItem(repository, storageItem); } }
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); } }
public long getLength() { return getFile().length(); }
public void delete() throws IOException { FileUtils.forceDelete( getFile() ); }