public static String encode (final String s, final String encoding) throws UnsupportedEncodingException { if ("utf-8".equalsIgnoreCase(encoding)) { return encodeUTF8(s); } return encodeBytes(s.getBytes(encoding)); }
private String getFormattedServiceUrl( final String urlService, final FileName file ) throws FileSystemException { if ( urlService == null ) { throw new NullPointerException(); } final String[] fileName = computeFileNames( file ); final RepositoryFileTreeDto fileInfo = lookupNode( fileName ); if ( fileInfo == null ) { throw new FileSystemException( FILE_NOT_FOUND, file ); } final String restName = normalizePath( file.getPath() ); return MessageFormat .format( urlService, URLEncoder.encodeUTF8( restName ).replaceAll( "\\!", "%21" ).replaceAll( "\\+", "%2B" ) ); }
URLEncoder.encodeUTF8( normalizePath( b.toString() ).replaceAll( "\\!", "%21" ).replaceAll( "\\+", "%2B" ) ) ); final WebResource resource = client.resource( url + service ); final ByteArrayInputStream stream = new ByteArrayInputStream( data );
public byte[] getData( final FileName file ) throws FileSystemException { final String[] fileName = computeFileNames( file ); final RepositoryFileTreeDto fileInfo = lookupNode( fileName ); if ( fileInfo == null ) { throw new FileSystemException( FILE_NOT_FOUND, file ); } final RepositoryFileDto fileDto = fileInfo.getFile(); if ( fileDto == null ) { throw new IllegalStateException( BI_SERVER_NULL_OBJECT ); } final String path = normalizePath( fileDto.getPath() ); String urlPath = path; try { urlPath = URLEncoder.encodeUTF8( path ).replaceAll( "\\!", "%21" ).replaceAll( "\\+", "%2B" ); } catch ( Exception ex ) { } //tcb final String service = MessageFormat.format( DOWNLOAD_SERVICE, urlPath ); return client.resource( url + service ).accept( MediaType.APPLICATION_XML_TYPE ).get( byte[].class ); }
public void createFolder( final FileName file ) throws FileSystemException { try { final String path = URLEncoder .encodeUTF8( URLDecoder.decode( normalizePath( file.getPath().replaceAll( "\\+", "%2B" ) ), "UTF-8" ) ) .replaceAll( "\\!", "%21" ); final String service = MessageFormat.format( CREATE_FOLDER_SERVICE, path ); final WebResource resource = client.resource( url + service ); final ClientResponse response = resource.type( "text/plain" ).put( ClientResponse.class, null ); if ( response.getStatus() == 200 ) { refresh(); } else { throw new FileSystemException( "Failed with error-code", response.getStatus() ); } } catch ( FileSystemException fse ) { throw fse; } catch ( Exception e ) { throw new FileSystemException( "Failed", e ); } }