Tuesday 15 July 2014

c# - Byte[] Split Up Into 1022 Length Sections Then Restored Not Matching Up -


I am trying to take a PDF document and submit it to a SAP structure through an MAPC website I am uploading. A byte array is required for SAP structure, which should be broken into 1022 length sections. The program works well till that point where I try to see the PDF document from SAP. Unfortunately, I can not see the PDF data stored in the SAP due to access rights. Therefore, I have created a sort MOCC program to match the byte array before sending the SAP (file content) and then it should look like returning from the SAP (File Content Post SAP).

The program compares byte arrays and finds the mismatched value at array 1022.

Is there a bug in my program that does not match byte arrays? They should match properly, right?

Claimed ClaimsMedicineMGR = New Claim Representation (); Expectancy claims currentclaimyignment = claim credentials MGR GetCurrentClaimsIdentity (); Var subpath = "~ / App_Data /" + currentclaimsIdentity.EmailAddress; Var destination path = path. Combine (server mappath (subpath), "LG WM3455H Speak Sheet PDF"); Byte [] fileContent = System.IO.File.ReadAllBytes (destinationPath); // Excuse it is going to do SAP var arrList = SAPServiceRequestRepository.CreateByteListForStructure (fileContent); Var Talk Feature List = New List & Lieutenant; Byte [] & gt; (); Foreach (byList) in batch [] b) mockStructureList.Add (b); // Now get it back from fake SAP var filecentant POSTSAP = new byte [fileContent.Count ()]; Var rowCounter = 0; Var prevLength = 0; Foreach (various objects in mockStructureList) {if (rowCounter == 0) System.Buffer.BlockCopy (item, 0, fileContentPostSAP, 0, item.Length); Other systems. Buffer. Blockcopy (item, 0, file system resource sap, prelong, item lang); RowCounter ++; PrevLength = item.Length; } // Compare the original array with a new var = (fileContent == fileContentPostSAP); (Var i = 0; i & lt; fileContent.Length; i ++) {if (fileContent [i]! = FileContentPostSAP [i]) New exception throw ("i =" + i + "| fileContent [i ] = "+ FileContent [i] +" | fileContentPostSAP [i] = "+ File Resource Post SAP [Ii]) ;; }

And here's the CreateByteListForStructure function:

  Public Fixed List & lt; Byte [] & gt; CreateByteListForStructure (byte [] fileContent) {var returnList = new list & lt; Byte [] & gt; (); {If (fileContent.Length - i & gt; = 1022) {var localByteArray = new byte [1022] for (Var i = 0; i & lt; fileContent.Length; i + = 1022); System.Buffer.BlockCopy (fileContent, i, localbetaare, 0, 1022); ReturnList.Add (localByteArray); } Else {var localByteArray = new byte [fileContent.Length - i]; System.Buffer.BlockCopy (fileContent, i, localByteArray, 0, fileContent.Length - i); ReturnList.Add (localByteArray); }} Return return list; }  

The code looks like a simple bug.

This loop, which rebuilds the array contents from blocks:

  var prevLength = 0; Foreach (various objects in mockStructureList) {if (rowCounter == 0) System.Buffer.BlockCopy (item, 0, fileContentPostSAP, 0, item.Length); Other systems. Buffer. Blockcopy (item, 0, file system resource sap, prelong, item lang); RowCounter ++; PrevLength = item.Length; }  

According to the block description, each block is 1022 bytes, which means that after the first running, prevLength is set to 1022, but after the next Again it is set to 1022 again .

prevLength will have the correct function:

  prevLength + = items Long; ^ | + - Added it  

Instead of moving it correctly to the block for a second time and then leaving it after it, the output will move one block one at a time in the array.

Actually you write block 0 in the right place, but leave all the other blocks on the top of block 1, zero 2 and then into the output array as zero.


No comments:

Post a Comment