@Override
	public int onWriteFile(String fileName, ByteBuffer buffer, long offset, DokanFileInfo arg3) throws DokanOperationException {
		FileHandle handle;
		synchronized (handles)
		{
			handle = handles.get(arg3.handle);
		}
		if (handle == null)
			throw new DokanOperationException(net.decasdev.dokan.WinError.ERROR_INVALID_HANDLE);
		
		if (!handle.write)
			throw new DokanOperationException(net.decasdev.dokan.WinError.ERROR_ACCESS_DENIED);
		
		try {
			fileSystem.write(handle, buffer, offset);
		} catch (DriveFullException e) {
			throw new DokanOperationException(net.decasdev.dokan.WinError.ERROR_DISK_FULL);
		} catch (PartIsLockedException e) {
			throw new DokanOperationException(net.decasdev.dokan.WinError.ERROR_INVALID_ACCESS);
		} catch (Exception e)
		{
			e.printStackTrace();
		}
		
		return buffer.limit();
	}