@Override
    public AcknowledgementService handle(LocalDevice localDevice, Address from, OctetString linkService)
            throws BACnetException {
        AtomicWriteFileAck response;

        BACnetObject obj;
        FileObject file;
        try {
            // Find the file.
            obj = localDevice.getObjectRequired(fileIdentifier);
            if (!(obj instanceof FileObject))
                throw new BACnetServiceException(ErrorClass.object, ErrorCode.rejectInconsistentParameters);
            file = (FileObject) obj;

            // Validation.
            FileAccessMethod fileAccessMethod = (FileAccessMethod) file
                    .getProperty(PropertyIdentifier.fileAccessMethod);
            if (fileData == null && fileAccessMethod.equals(FileAccessMethod.streamAccess) || fileData != null
                    && fileAccessMethod.equals(FileAccessMethod.recordAccess))
                throw new BACnetErrorException(getChoiceId(), ErrorClass.object, ErrorCode.invalidFileAccessMethod);
        }
        catch (BACnetServiceException e) {
            throw new BACnetErrorException(getChoiceId(), e);
        }

        if (fileData == null) {
            throw new NotImplementedException();
        }

        long start = fileStart.longValue();

        if (start > file.length())
            throw new BACnetErrorException(getChoiceId(), ErrorClass.object, ErrorCode.invalidFileStartPosition);

        try {
            file.writeData(start, fileData);
            response = new AtomicWriteFileAck(fileData == null, fileStart);
        }
        catch (IOException e) {
            throw new BACnetErrorException(getChoiceId(), ErrorClass.object, ErrorCode.fileAccessDenied);
        }

        return response;
    }