// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/InsufficientCapacityException.java
// public class InsufficientCapacityException extends Exception {
// 
//     public InsufficientCapacityException() {
//     }
// 
//     public InsufficientCapacityException(String message) {
//         super(message);
//     }
// 
//     public InsufficientCapacityException(StackTraceElement[] stackTraceElements) {
//         setStackTrace(stackTraceElements);
//     }
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/ReadOnlyTagException.java
// public class ReadOnlyTagException extends TagNotWritableException {
// 
//     public ReadOnlyTagException() {
//     }
// 
//     public ReadOnlyTagException(String message) {
//         super(message);
//     }
// 
// 
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NdefWrite.java
// public interface NdefWrite {
//     /**
//      * Write message to ndef
//      *
//      * @param message
//      *         to write
//      * @param ndef
//      *         from tag to write to
//      *
//      * @return true if success, false if ndef == null || message == null
//      *
//      * @throws ReadOnlyTagException
//      *         if tag is read-only
//      * @throws InsufficientCapacityException
//      *         if the tag's capacity is not sufficient
//      * @throws FormatException
//      *         if the message is malformed
//      */
//     boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
// 
//     /**
//      * Write message to ndef and make readonly
//      *
//      * @see NdefWrite#writeToNdef(android.nfc.NdefMessage, android.nfc.tech.Ndef)
//      */
//     boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
// 
//     /**
//      * Write the message to an NdefFormatable
//      * @param message to write
//      * @param ndefFormatable to write to
//      * @return true if success, false if ndefFormatable == null || message == null
//      * @throws FormatException
//      */
//     boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException;
// 
//     /**
//      * Write the message to an NdefFormatable and make readonly
//      * @see NdefWrite#writeToNdefFormatable(android.nfc.NdefMessage, android.nfc.tech.NdefFormatable)
//      */
//     boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException;
// 
// }


import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
import be.appfoundry.nfclibrary.utilities.interfaces.NdefWrite;
import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.TagLostException;
import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.util.Log;
import java.io.IOException;
                try {
                    ndef.close();
                } catch (IOException e) {
                    Log.v(TAG, "IOException occurred at closing.", e);
                }
            }
        }
        return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
        setReadOnly(true);
        boolean result = writeToNdef(message, ndef);
        setReadOnly(false);
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException {
        setReadOnly(true);
        boolean result = writeToNdefFormatable(message, ndefFormat);
        setReadOnly(false);

// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/InsufficientCapacityException.java
// public class InsufficientCapacityException extends Exception {
// 
//     public InsufficientCapacityException() {
//     }
// 
//     public InsufficientCapacityException(String message) {
//         super(message);
//     }
// 
//     public InsufficientCapacityException(StackTraceElement[] stackTraceElements) {
//         setStackTrace(stackTraceElements);
//     }
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/ReadOnlyTagException.java
// public class ReadOnlyTagException extends TagNotWritableException {
// 
//     public ReadOnlyTagException() {
//     }
// 
//     public ReadOnlyTagException(String message) {
//         super(message);
//     }
// 
// 
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NdefWrite.java
// public interface NdefWrite {
//     /**
//      * Write message to ndef
//      *
//      * @param message
//      *         to write
//      * @param ndef
//      *         from tag to write to
//      *
//      * @return true if success, false if ndef == null || message == null
//      *
//      * @throws ReadOnlyTagException
//      *         if tag is read-only
//      * @throws InsufficientCapacityException
//      *         if the tag's capacity is not sufficient
//      * @throws FormatException
//      *         if the message is malformed
//      */
//     boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
// 
//     /**
//      * Write message to ndef and make readonly
//      *
//      * @see NdefWrite#writeToNdef(android.nfc.NdefMessage, android.nfc.tech.Ndef)
//      */
//     boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
// 
//     /**
//      * Write the message to an NdefFormatable
//      * @param message to write
//      * @param ndefFormatable to write to
//      * @return true if success, false if ndefFormatable == null || message == null
//      * @throws FormatException
//      */
//     boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException;
// 
//     /**
//      * Write the message to an NdefFormatable and make readonly
//      * @see NdefWrite#writeToNdefFormatable(android.nfc.NdefMessage, android.nfc.tech.NdefFormatable)
//      */
//     boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException;
// 
// }


// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/sync/NdefWriteImpl.java
import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
import be.appfoundry.nfclibrary.utilities.interfaces.NdefWrite;
import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.TagLostException;
import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.util.Log;
import java.io.IOException;

                try {
                    ndef.close();
                } catch (IOException e) {
                    Log.v(TAG, "IOException occurred at closing.", e);
                }
            }
        }
        return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
        setReadOnly(true);
        boolean result = writeToNdef(message, ndef);
        setReadOnly(false);
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException {
        setReadOnly(true);
        boolean result = writeToNdefFormatable(message, ndefFormat);
        setReadOnly(false);

        return result;