[[Main]] .+ [[What_Is_Subversion_For|What Is Subversion For]] .+ [[Setting_Up_A_Subversion_Repository|Setting Up A Subversion Repository]] .+ [[SVNKit_Architecture|SVNKit Architecture]] .+ [[Getting_Started_With_SVNKit|Getting Started With SVNKit]] .+ [[Authentication]] .+ [[Managing_Repository_With_SVNKit|Managing Repository With SVNKit]] .+ [[Printing_Out_A_Subversion_Repository_Tree|Printing Out A Subversion Repository Tree]] .- Printing Out File Contents .+ [[Printing_Out_Repository_History|Printing Out Repository History]] .+ [[Committing_To_A_Repository|Editing operation: committing to a repository]] .+ [[Updating_From_A_Repository|Editing Operation: receiving changes from a repository]] .+ [[Replicating_An_Existing_Repository|Replicating An Existing Repository]] .+ [[Managing_A_Working_Copy|Managing A Working Copy]] ---- = Printing Out File Contents = In this example we will study how to read contents of a file from a particular revision of a repository. The first steps are just like in the previous example: {{{#!java ... public class DisplayFile { public static void main( String[] args ) { DAVRepositoryFactory.setup( ); String url = "http://svn.svnkit.com/repos/svnkit/trunk"; String name = "anonymous"; String password = "anonymous"; String filePath = "www/license.html"; SVNRepository repository = null; try { repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) ); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name , password ); repository.setAuthenticationManager( authManager ); SVNNodeKind nodeKind = repository.checkPath( filePath , -1 ); if ( nodeKind == SVNNodeKind.NONE ) { System.err.println( "There is no entry at '" + url + "'." ); System.exit( 1 ); } else if ( nodeKind == SVNNodeKind.DIR ) { System.err.println( "The entry at '" + url + "' is a directory while a file was expected." ); System.exit( 1 ); } ... }}} Now when we are sure that our url corresponds to a file we read its contents into an {{{OutputStream}}} and collect its properties into a {{{Map}}}. {{{#!java ... Map fileProperties = new HashMap( ); ByteArrayOutputStream baos = new ByteArrayOutputStream( ); repository.getFile( filePath , -1 , fileProperties , baos ); ... }}} Then we find out whether the file is a text or binary file using the MIME type property. If it's a binary we don't print its contents. We also print out versioned file properties. {{{#!java ... String mimeType = ( String ) fileProperties.get( SVNProperty.MIME_TYPE ); boolean isTextType = SVNProperty.isTextMimeType( mimeType ); Iterator iterator = fileProperties.keySet( ).iterator( ); while ( iterator.hasNext( ) ) { String propertyName = ( String ) iterator.next( ); String propertyValue = ( String ) fileProperties.get( propertyName ); System.out.println( "File property: " + propertyName + "=" + propertyValue ); } if ( isTextType ) { System.out.println( "File contents:" ); System.out.println( ); try { baos.writeTo( System.out ); } catch ( IOException ioe ) { ioe.printStackTrace( ); } } else { System.out.println( "Not a text file." ); } ... }}} And finally we run the program and have the following output in our console: {{{ File property: svn:entry:revision=2802 File property: svn:entry:checksum=435f2f0d33d12907ddb6dfd611825ec9 File property: svn:wc:ra_dav:version-url=/repos/svnkit/!svn/ver/2795/trunk/www/license.html File property: svn:entry:last-author=alex File property: svn:entry:committed-date=2006-11-13T21:34:27.908657Z File property: svn:entry:committed-rev=2795 File contents: SVNKit :: License

The TMate Open Source License.

......................................
---------------------------------------------
Repository latest revision: 2802
}}}

----
Download the [[http://svn.svnkit.com/repos/svnkit/tags/1.3.5/doc/examples/src/org/tmatesoft/svn/examples/repository/DisplayFile.java|example program source code]].