<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[A small bug in the atomicwritefilerequest]]></title><description><![CDATA[<p dir="auto">basically it works.<br />
but the standard says exactly when a bacneterrorexception has to be thrown:</p>
<ul>
<li>negative start</li>
<li>start exceeds the filesize</li>
</ul>
<p dir="auto">at the same time a few internal 'things' should be checked. when the device property backupAndRestoreState<br />
is set to preparingForBackup or preparingForRestore the the atomic read/write requests are dangerous and could deliver<br />
faulty results. thus throw a device configuration in progress bacnetserviceexception as written in the standard.</p>
<pre><code>
	@Override
	public AcknowledgementService handle(LocalDevice localDevice, Address from, Network network) throws BACnetException
	{
		AtomicReadFileAck response;

		BACnetObject obj;
		FileObject file;
		try
		{
			// Find the file.
			obj = localDevice.getObjectRequired(fileIdentifier);
			if (!(obj instanceof FileObject))
			{
				System.out.println("File access request on an object that is not a file");
				throw new BACnetServiceException(ErrorClass.object, ErrorCode.rejectInconsistentParameters);
			}
			// check for status (backup/restore)
			BackupState bsOld = (BackupState) localDevice.getConfiguration().getProperty(
					PropertyIdentifier.backupAndRestoreState);
			if (bsOld.intValue() == BackupState.preparingForBackup.intValue()
					|| bsOld.intValue() == BackupState.preparingForRestore.intValue())
			{
				// send error: device configuration in progress as response
				throw new BACnetServiceException(ErrorClass.device, ErrorCode.configurationInProgress);
			}

			file = (FileObject) obj;

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

		if (recordAccess)
			throw new NotImplementedException();

		long start = fileStartPosition.longValue();
		long length = requestedCount.longValue();

		/* 
		 * throw an exception when the following conditions are met:
		 * - start is a negative number
		 * - start exceeds the length of the file object
		 */
		if (start &gt; file.length() || start &lt; 0)
			throw new BACnetErrorException(getChoiceId(), ErrorClass.object, ErrorCode.invalidFileStartPosition);

		try
		{
			response = new AtomicReadFileAck(new Boolean(file.length() &lt;= start + length), fileStartPosition, file.readData(
					start, length));
		}
		catch (IOException e)
		{
			throw new BACnetErrorException(getChoiceId(), ErrorClass.object, ErrorCode.fileAccessDenied);
		}

		return response;
	}

</code></pre>
<p dir="auto">that's it - works nicely.<br />
robert</p>
]]></description><link>https://forum.mango-os.com/topic/793/a-small-bug-in-the-atomicwritefilerequest</link><generator>RSS for Node</generator><lastBuildDate>Wed, 17 Jun 2026 03:13:30 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/793.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 29 Mar 2011 18:37:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to A small bug in the atomicwritefilerequest on Thu, 31 Mar 2011 17:48:19 GMT]]></title><description><![CDATA[<p dir="auto">Ok. I recall (but at the moment can't confirm) that there was some problem with this during testing of the original implementation, but i'll go with your version.</p>
]]></description><link>https://forum.mango-os.com/post/5631</link><guid isPermaLink="true">https://forum.mango-os.com/post/5631</guid><dc:creator><![CDATA[mlohbihler]]></dc:creator><pubDate>Thu, 31 Mar 2011 17:48:19 GMT</pubDate></item><item><title><![CDATA[Reply to A small bug in the atomicwritefilerequest on Thu, 31 Mar 2011 10:17:36 GMT]]></title><description><![CDATA[<p dir="auto">hello matt,</p>
<p dir="auto">a zero length file should be readable without error.<br />
and the standard says explicitly when the file size <strong>exceeds</strong>.</p>
<p dir="auto">if (start &lt; 0 || start &gt; file.length()</p>
<p dir="auto">is correct when reading the spec.<br />
and another commercial stack shows the same behaviour with the upper mod.</p>
<p dir="auto">regards<br />
robert</p>
]]></description><link>https://forum.mango-os.com/post/5630</link><guid isPermaLink="true">https://forum.mango-os.com/post/5630</guid><dc:creator><![CDATA[robert bouwens]]></dc:creator><pubDate>Thu, 31 Mar 2011 10:17:36 GMT</pubDate></item><item><title><![CDATA[Reply to A small bug in the atomicwritefilerequest on Thu, 31 Mar 2011 01:02:43 GMT]]></title><description><![CDATA[<p dir="auto">Should the fileStartPosition condition not be:</p>
<pre><code>        if (start &amp;lt; 0 || start &amp;gt;= file.length())

</code></pre>
<p dir="auto">?</p>
<p dir="auto">Or do you intend that if start == file.length() that a 0 result should be returned?</p>
]]></description><link>https://forum.mango-os.com/post/5629</link><guid isPermaLink="true">https://forum.mango-os.com/post/5629</guid><dc:creator><![CDATA[mlohbihler]]></dc:creator><pubDate>Thu, 31 Mar 2011 01:02:43 GMT</pubDate></item><item><title><![CDATA[Reply to A small bug in the atomicwritefilerequest on Thu, 31 Mar 2011 00:28:13 GMT]]></title><description><![CDATA[<p dir="auto">Ah, that explains it. The title of the post threw me off.</p>
]]></description><link>https://forum.mango-os.com/post/5627</link><guid isPermaLink="true">https://forum.mango-os.com/post/5627</guid><dc:creator><![CDATA[mlohbihler]]></dc:creator><pubDate>Thu, 31 Mar 2011 00:28:13 GMT</pubDate></item><item><title><![CDATA[Reply to A small bug in the atomicwritefilerequest on Wed, 30 Mar 2011 11:22:30 GMT]]></title><description><![CDATA[<p dir="auto">hi matt,<br />
sorry for being unclear:</p>
<pre><code>public class AtomicReadFileRequest extends ConfirmedRequestService
{
	private static final long serialVersionUID = -279843621668191530L;

	public static final byte TYPE_ID = 6;

	private final ObjectIdentifier fileIdentifier;
	private final boolean recordAccess;
	private final SignedInteger fileStartPosition;
	private final UnsignedInteger requestedCount;

	public AtomicReadFileRequest(ObjectIdentifier fileIdentifier, boolean recordAccess, SignedInteger fileStartPosition,
			UnsignedInteger requestedCount)
	{
		this.fileIdentifier = fileIdentifier;
		this.recordAccess = recordAccess;
		this.fileStartPosition = fileStartPosition;
		this.requestedCount = requestedCount;
	}

</code></pre>
<p dir="auto">the varaible is the standard member variable defined in the class.</p>
<p dir="auto">regards<br />
robert</p>
]]></description><link>https://forum.mango-os.com/post/5624</link><guid isPermaLink="true">https://forum.mango-os.com/post/5624</guid><dc:creator><![CDATA[robert bouwens]]></dc:creator><pubDate>Wed, 30 Mar 2011 11:22:30 GMT</pubDate></item><item><title><![CDATA[Reply to A small bug in the atomicwritefilerequest on Wed, 30 Mar 2011 03:38:05 GMT]]></title><description><![CDATA[<p dir="auto">What's "recordAccess"? It isn't defined anywhere.</p>
]]></description><link>https://forum.mango-os.com/post/5622</link><guid isPermaLink="true">https://forum.mango-os.com/post/5622</guid><dc:creator><![CDATA[mlohbihler]]></dc:creator><pubDate>Wed, 30 Mar 2011 03:38:05 GMT</pubDate></item></channel></rss>