@Override protected void execute() throws Exception { FileObject targetDirectory = targetFile.getParent(); FileObjectRepository targetRepository = new FileObjectRepository( targetDirectory ); targetRoot = targetRepository.getRoot(); suffix = getSuffix( targetPath ); Path p = Paths.get( targetFile.getName().getPath() ); filename = IOUtils.getInstance().stripFileExtension( p.getFileName().toString() ); ReportProcessor reportProcessor = createReportProcessor( null ); try { reportProcessor.processReport(); } finally { reportProcessor.close(); } }
protected String getSuffix( final String filename ) { final String suffix = IOUtils.getInstance().getFileExtension( filename ); if ( suffix.length() == 0 ) { return ""; //$NON-NLS-1$ } return suffix.substring( 1 ); } }
public void writeContent( final ZipEntry entry, final InputStream in, final int method, final int compression ) throws IOException { zipOutputStream.setMethod( method ); zipOutputStream.setLevel( compression ); zipOutputStream.putNextEntry( entry ); IOUtils.getInstance().copyStreams( in, zipOutputStream ); zipOutputStream.closeEntry(); } }
public URLResourceData( final ResourceKey key ) { if ( key == null ) { throw new NullPointerException(); } this.modificationDate = -1; this.key = key; this.url = (URL) key.getIdentifier(); // for the ease of implementation, we take the file name from the URL. // Feel free to add a 'Content-Disposition' parser with all details :) this.filename = IOUtils.getInstance().getFileName( url ); }
/** * Copies the given reader to the character stream. This method should be used for large chunks of data. * * @param reader the reader providing the text. * @throws IOException if there is a problem writing to the character stream. */ public void writeStream( final Reader reader ) throws IOException { IOUtils.getInstance().copyWriter( reader, writer ); support.setLineEmpty( false ); }
final String directory = IOUtils.getInstance().getPath( path ); final String fileNameWExt = IOUtils.getInstance().getFileName( path ); String fileExtension = IOUtils.getInstance().getFileExtension( fileNameWExt ); if ( StringUtils.isEmpty( fileExtension ) ) { fileExtension = "." + mimeRegistry.getSuffix( mimeType ); final String fileName = IOUtils.getInstance().stripFileExtension( fileNameWExt ); String pattern = stripTrailingNumbers( fileName ); if ( pattern == null ) {
private Object evaluate( final Expression ex ) throws IOException, SQLException { final Object retval = ex.getValue(); if ( retval instanceof Clob ) { return IOUtils.getInstance().readClob( (Clob) retval ); } if ( retval instanceof Blob ) { return IOUtils.getInstance().readBlob( (Blob) retval ); } return retval; } }
throw new BundleWriterException( "Data-factory writer did not create a file for " + df.getClass() ); final String refFile = IOUtils.getInstance().createRelativePath( file, fileName ); xmlWriter.writeTag( CompoundDataFactoryModule.NAMESPACE, "data-factory", "href", refFile, XmlWriterSupport.CLOSE );
/** * @noinspection IOResourceOpenedButNotSafelyClosed */ private byte[] extractData( final InputSource input ) throws IOException { final InputStream byteStream = input.getByteStream(); if ( byteStream != null ) { try { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); IOUtils.getInstance().copyStreams( byteStream, bout ); return bout.toByteArray(); } finally { byteStream.close(); } } final Reader characterStream = input.getCharacterStream(); if ( characterStream == null ) { throw new IOException( "InputSource has neither an Byte nor a CharacterStream" ); } try { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); final OutputStreamWriter owriter = new OutputStreamWriter( bout ); IOUtils.getInstance().copyWriter( characterStream, owriter ); owriter.close(); return bout.toByteArray(); } finally { characterStream.close(); } }
private String extractFilename( final ResourceData resourceData ) { final String filename = (String) resourceData.getAttribute( ResourceData.FILENAME ); if ( filename == null ) { return "image"; } final String pureFileName = IOUtils.getInstance().getFileName( filename ); return IOUtils.getInstance().stripFileExtension( pureFileName ); }
private String computeStringValue(final Object retval) { if (retval instanceof Clob) { try { return IOUtils.getInstance().readClob((Clob) retval); } catch (Exception e) { return null; } } if (retval != null) { return retval.toString(); } return null; }
/** * Returns an unique name for the given pattern, producing a file relative to the parent file name. The returned path * will be an <b>absolute</b> path starting from the root of the bundle. When linking to this path via href-references * that imply relative paths, use {@link org.pentaho.reporting.libraries.base.util.IOUtils#createRelativePath(java * .lang.String, * java.lang.String)} to transform the absolute path returned here into a path relative to your current context. * * @param bundle the document bundle for which we seek a new unique file name. * @param parent the parent path to which the pattern is relative to. * @param pattern the file name pattern. We expect one parameter only. * @return the unique file name, never null. * @throws IllegalStateException if the first 2 million entries we test do not yield a unique name we can use. */ public static String getUniqueName( final DocumentBundle bundle, final String parent, final String pattern ) { final String fullPattern = IOUtils.getInstance().getAbsolutePath( pattern, parent ); return getUniqueName( bundle, fullPattern ); }
throw new NullPointerException( "baseURL must not be null." ); if ( isFileStyleProtocol( url ) && isSameService( url, baseURL ) ) { final List<String> urlName = parseName( getPath( url ) ); final List<String> baseName = parseName( getPath( baseURL ) ); final String query = getQuery( url ); if ( !isPath( baseURL ) ) { baseName.remove( baseName.size() - 1 ); int commonIndex = startsWithUntil( urlName, baseName ); if ( commonIndex == 0 ) { return url.toExternalForm(); return formatName( retval, query );
if ( IOUtils.getInstance().isSubDirectory( file, child ) == false ) { throw new ContentIOException( "The given entry does not point to a sub-directory of this content-location" );
try { final Blob b = (Blob) o; final byte[] data = IOUtils.getInstance().readBlob( b ); final ResourceManager resManager = runtime.getProcessingContext().getResourceManager(); final Resource resource = resManager.createDirectly( data, Image.class );
/** * Sets the parameters of this description object to match the supplied object. * * @param o * the object (should be an instance of <code>URL</code>). * @throws ObjectFactoryException * if the object is not an instance of <code>URL</code>. */ public void setParameterFromObject( final Object o ) throws ObjectFactoryException { if ( !( o instanceof URL ) ) { throw new ObjectFactoryException( "Is no instance of java.net.URL" ); } final URL comp = (URL) o; final String baseURL = getConfig().getConfigProperty( AbstractXmlResourceFactory.CONTENTBASE_KEY ); try { final URL bURL = new URL( baseURL ); if ( ObjectUtilities.equal( bURL, comp ) ) { setParameter( "value", null ); } else { setParameter( "value", IOUtils.getInstance().createRelativeURL( comp, bURL ) ); } } catch ( Exception e ) { URLObjectDescription.logger.warn( "BaseURL is invalid: ", e ); setParameter( "value", comp.toExternalForm() ); } }
/** * Copies the InputStream into the OutputStream, until the end of the stream has been reached. This method uses a * buffer of 4096 kbyte. * * @param in the inputstream from which to read. * @param out the outputstream where the data is written to. * @throws java.io.IOException if a IOError occurs. */ public void copyStreams( final InputStream in, final OutputStream out ) throws IOException { copyStreams( in, out, 4096 ); }
/** * Extracts the file name from the URL. * * @param url the url. * @return the extracted filename. */ public String getFileName( final URL url ) { final String fileRaw = url.getFile(); final int query = fileRaw.lastIndexOf( '?' ); final String file; if ( query == -1 ) { file = fileRaw; } else { file = fileRaw.substring( 0, query ); } // Now the processing is the same as if it is a string return getFileName( file ); }
/** * Copies the contents of the Reader into the Writer, until the end of the stream has been reached. This method uses a * buffer of 4096 kbyte. * * @param in the reader from which to read. * @param out the writer where the data is written to. * @throws java.io.IOException if a IOError occurs. */ public void copyWriter( final Reader in, final Writer out ) throws IOException { copyWriter( in, out, 4096 ); }
/** * Returns <code>true</code> if the URL represents a path, and <code>false</code> otherwise. * * @param baseURL the URL. * @return A boolean. */ private boolean isPath( final URL baseURL ) { final String path = getPath( baseURL ); if ( path.length() > 0 && path.charAt( path.length() - 1 ) == '/' ) { return true; } else if ( "file".equals( baseURL.getProtocol() ) ) { final File f = new File( path ); try { if ( f.isDirectory() ) { return true; } } catch ( SecurityException se ) { // ignored ... } } return false; }