bundles/org.eclipse.packagedrone.sec.service.admin/src/org/eclipse/packagedrone/sec/service/admin/GodModeService.java
protected void writeAnnounceFile ( final String adminToken )
    {
        final Path path = ANNOUNCE_FILE.toPath ();

        /*
         * Try to delete the file first. We don't care about the result
         * since the next operation will try to create a new file anyway.
         *
         * However by deleting it first, we try to ensure that the initial
         * file permissions are set. If the file exists these would not be
         * changed.
         */

        ANNOUNCE_FILE.delete ();

        // posix

        final FileAttribute<?>[] attrs;
        if ( ANNOUNCE_FILE_POSIX )
        {
            final Set<PosixFilePermission> perms = EnumSet.of ( PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE );
            attrs = new FileAttribute<?>[] { PosixFilePermissions.asFileAttribute ( perms ) };
        }
        else
        {
            attrs = new FileAttribute<?>[0];
        }

        final Set<? extends OpenOption> options = EnumSet.of ( StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING );

        try ( SeekableByteChannel sbc = Files.newByteChannel ( path, options, attrs ) )
        {
            final StringWriter sw = new StringWriter ();
            final PrintWriter writer = new PrintWriter ( sw );
            writer.format ( "user=%s%n", NAME );
            writer.format ( "password=%s%n", adminToken );
            writer.close ();

            final ByteBuffer data = ByteBuffer.wrap ( sw.toString ().getBytes ( StandardCharsets.UTF_8 ) );
            while ( data.hasRemaining () )
            {
                sbc.write ( data );
            }
        }
        catch ( final UnsupportedOperationException e )
        {
            System.err.format ( "WARNING: Failed to write out announce file with secured posix permissions. If you are on a non-posix platform (e.g. Windows), you might need to set the system property '%s' to 'true'%n", PROP_NOT_POSIX );
        }
        catch ( final IOException e )
        {
            System.err.println ( "WARNING: Unable to write announce file: " + ExceptionHelper.getMessage ( e ) );
        }
    }
protected void writeAnnounceFile ( final String adminToken )
    {
        final Path path = ANNOUNCE_FILE.toPath ();

        /*
         * Try to delete the file first. We don't care about the result
         * since the next operation will try to create a new file anyway.
         *
         * However by deleting it first, we try to ensure that the initial
         * file permissions are set. If the file exists these would not be
         * changed.
         */

        ANNOUNCE_FILE.delete ();

        // posix

        final FileAttribute<?>[] attrs;
        if ( ANNOUNCE_FILE_POSIX )
        {
            final Set<PosixFilePermission> perms = EnumSet.of ( PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE );
            attrs = new FileAttribute<?>[] { PosixFilePermissions.asFileAttribute ( perms ) };
        }
        else
        {
            attrs = new FileAttribute<?>[0];
        }

        final Set<? extends OpenOption> options = EnumSet.of ( StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING );

        try ( SeekableByteChannel sbc = Files.newByteChannel ( path, options, attrs ) )
        {
            final StringWriter sw = new StringWriter ();
            final PrintWriter writer = new PrintWriter ( sw );
            writer.format ( "user=%s%n", NAME );
            writer.format ( "password=%s%n", adminToken );
            writer.close ();

            final ByteBuffer data = ByteBuffer.wrap ( sw.toString ().getBytes ( StandardCharsets.UTF_8 ) );
            while ( data.hasRemaining () )
            {
                sbc.write ( data );
            }
        }
        catch ( final UnsupportedOperationException e )
        {
            System.err.format ( "WARNING: Failed to write out announce file with secured posix permissions. If you are on a non-posix platform (e.g. Windows), you might need to set the system property '%s' to 'true'%n", PROP_NOT_POSIX );
        }
        catch ( final IOException e )
        {
            System.err.println ( "WARNING: Unable to write announce file: " + ExceptionHelper.getMessage ( e ) );
        }
    }
Write out the announce file <br>
Writing a file like this seems a little bit strange from a Java
perspective. However, there seems to be no other way to create a file
with a provided set of initial file attributes other than
{@link Files#newByteChannel(java.nio.file.Path, Set, FileAttribute...)}.
All other methods don't access file attributes.

@param adminToken
The admin token to write out