JeffT Member Licensed User Aug 14, 2020 #1 Hi all. Ive been creating a text file using TextWriter. When I examine the result, it has been truncated at 04000 Hex bytes in size.. it's incomplete. Is this an Android limit, or TextWriter, or what?
Hi all. Ive been creating a text file using TextWriter. When I examine the result, it has been truncated at 04000 Hex bytes in size.. it's incomplete. Is this an Android limit, or TextWriter, or what?
mcqueccu Expert Licensed User Longtime User Aug 14, 2020 #3 use B4X: Copy File.WriteString() Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Aug 16, 2020 #4 JeffT said: Is this an Android limit, or TextWriter, or what? Click to expand... Third option. I guess that you logged the file content. Log truncates messages longer than 4000 characters. TextWriter or File.WriteString will never truncate anything. If there isn't enough memory (and there is) then there will be an error. Tip: don't use TextWriter. Use File.WriteString or WriteList. Upvote 0
JeffT said: Is this an Android limit, or TextWriter, or what? Click to expand... Third option. I guess that you logged the file content. Log truncates messages longer than 4000 characters. TextWriter or File.WriteString will never truncate anything. If there isn't enough memory (and there is) then there will be an error. Tip: don't use TextWriter. Use File.WriteString or WriteList.
JeffT Member Licensed User Aug 16, 2020 #5 Hmm. Wasnt using logging.. just a loop with TextWriter. I did want to process each item in my list with a replace() as they were written out. To make a single writable string for WriteString, Id have to join a lot of strings, and that takes a very long time when debugging. (not on release, but I do need to debug) I'll see what happens with Writelist Upvote 0
Hmm. Wasnt using logging.. just a loop with TextWriter. I did want to process each item in my list with a replace() as they were written out. To make a single writable string for WriteString, Id have to join a lot of strings, and that takes a very long time when debugging. (not on release, but I do need to debug) I'll see what happens with Writelist
OliverA Expert Licensed User Longtime User Aug 16, 2020 #6 JeffT said: Id have to join a lot of strings, and that takes a very long time when debugging. Click to expand... How are you joining your strings? Upvote 0
JeffT said: Id have to join a lot of strings, and that takes a very long time when debugging. Click to expand... How are you joining your strings?
Alessandro71 Well-Known Member Licensed User Longtime User Aug 16, 2020 #7 Erel said: Tip: don't use TextWriter. Use File.WriteString or WriteList. Click to expand... I'm also fighting with TextWriter during my attempts to port code to multiple platforms, since TextWriter is not available in B4i. As I'm writing one line a time as they are produced (actually a logging module), File.WriteString or File.WriteList are not suitable, since they write all the file at once, with no append option available. Or am I missing something? Upvote 0
Erel said: Tip: don't use TextWriter. Use File.WriteString or WriteList. Click to expand... I'm also fighting with TextWriter during my attempts to port code to multiple platforms, since TextWriter is not available in B4i. As I'm writing one line a time as they are produced (actually a logging module), File.WriteString or File.WriteList are not suitable, since they write all the file at once, with no append option available. Or am I missing something?
JeffT Member Licensed User Aug 17, 2020 #8 I was using s = s & <newvalue> I've switched to Writelist and that seems to work (instead of writing line by line, I now add to a list then dump the lot) , but I suspect a bug in TextWriter. Upvote 0
I was using s = s & <newvalue> I've switched to Writelist and that seems to work (instead of writing line by line, I now add to a list then dump the lot) , but I suspect a bug in TextWriter.
Erel B4X founder Staff member Licensed User Longtime User Aug 17, 2020 #9 JeffT said: but I suspect a bug in TextWriter. Click to expand... Not very likely as this is a very stable API. If you can reproduce it in a small project then please do. Tip: Use StringBuilder when you need to concatenate many strings. It will be much much faster. Upvote 0
JeffT said: but I suspect a bug in TextWriter. Click to expand... Not very likely as this is a very stable API. If you can reproduce it in a small project then please do. Tip: Use StringBuilder when you need to concatenate many strings. It will be much much faster.
Alessandro71 Well-Known Member Licensed User Longtime User Aug 17, 2020 #10 JeffT said: I was using s = s & <newvalue> I've switched to Writelist and that seems to work (instead of writing line by line, I now add to a list then dump the lot) , but I suspect a bug in TextWriter. Click to expand... looks like a waste of memory and processing time, building a new string every time and rewriting the file. if something bad happens in between, you’re losing the whole file, which defies the purpose of a progressive log, in my use case Upvote 0
JeffT said: I was using s = s & <newvalue> I've switched to Writelist and that seems to work (instead of writing line by line, I now add to a list then dump the lot) , but I suspect a bug in TextWriter. Click to expand... looks like a waste of memory and processing time, building a new string every time and rewriting the file. if something bad happens in between, you’re losing the whole file, which defies the purpose of a progressive log, in my use case
Erel B4X founder Staff member Licensed User Longtime User Aug 17, 2020 #11 If you are writing a logs file then open it with File.OpenOutput with Append = True. Write the string. You can do it with OutputStream.Write. Upvote 0
If you are writing a logs file then open it with File.OpenOutput with Append = True. Write the string. You can do it with OutputStream.Write.
Alessandro71 Well-Known Member Licensed User Longtime User Aug 17, 2020 #12 Erel said: If you are writing a logs file then open it with File.OpenOutput with Append = True. Write the string. You can do it with OutputStream.Write. Click to expand... that’s what I’m doing, replacing the TextWriter class with a TextLogger one. just wondering why this isn’t available cross platform... Upvote 0
Erel said: If you are writing a logs file then open it with File.OpenOutput with Append = True. Write the string. You can do it with OutputStream.Write. Click to expand... that’s what I’m doing, replacing the TextWriter class with a TextLogger one. just wondering why this isn’t available cross platform...
Erel B4X founder Staff member Licensed User Longtime User Aug 17, 2020 #13 Everything needed is available: Code: Copy Public Sub LogToFile (msg As String) Dim out As OutputStream = File.OpenOutput(xui.DefaultFolder, "log.txt", True) 'you might want to add: msg = msg & CRLF Dim b() As Byte = msg.GetBytes("UTF8") out.WriteBytes(b, 0, b.Length) out.Close End Sub Upvote 0
Everything needed is available: Code: Copy Public Sub LogToFile (msg As String) Dim out As OutputStream = File.OpenOutput(xui.DefaultFolder, "log.txt", True) 'you might want to add: msg = msg & CRLF Dim b() As Byte = msg.GetBytes("UTF8") out.WriteBytes(b, 0, b.Length) out.Close End Sub
Alessandro71 Well-Known Member Licensed User Longtime User Aug 17, 2020 #14 Erel said: Everything needed is available: Code: Copy Public Sub LogToFile (msg As String) Dim out As OutputStream = File.OpenOutput(xui.DefaultFolder, "log.txt", True) 'you might want to add: msg = msg & CRLF Dim b() As Byte = msg.GetBytes("UTF8") out.WriteBytes(b, 0, b.Length) out.Close End Sub Click to expand... no doubt it can be done, I was just surprised to not find such a basic class not available on all platforms. Upvote 0
Erel said: Everything needed is available: Code: Copy Public Sub LogToFile (msg As String) Dim out As OutputStream = File.OpenOutput(xui.DefaultFolder, "log.txt", True) 'you might want to add: msg = msg & CRLF Dim b() As Byte = msg.GetBytes("UTF8") out.WriteBytes(b, 0, b.Length) out.Close End Sub Click to expand... no doubt it can be done, I was just surprised to not find such a basic class not available on all platforms.
rbghongade Well-Known Member Licensed User Longtime User Aug 17, 2020 #15 Dear friends, I am using TextWriter in one of my B4J based projects. The files are created as soon as I get MQTT message. Can it be the reason , that after a month or so of logging, I get GC limit error? I had raised this question and Erel suggested me to check the dump file, but it was not possible due to client location. Upvote 0
Dear friends, I am using TextWriter in one of my B4J based projects. The files are created as soon as I get MQTT message. Can it be the reason , that after a month or so of logging, I get GC limit error? I had raised this question and Erel suggested me to check the dump file, but it was not possible due to client location.
Erel B4X founder Staff member Licensed User Longtime User Aug 17, 2020 #16 It depends on how you use it. I cannot say more without more information (better in a new thread). Upvote 0
moster67 Expert Licensed User Longtime User Aug 18, 2020 #17 Maybe this tool can help you while debugging. [B4X Tool] - B4XIDEViewer V. 1.0 [B4X Tool] - B4XIDEViewer V. 1.0 What is B4XIDEViewer? -It’s a B4X Tool which can show bitmaps, images and saved pictures from your B4XIDE on your computer. You can also play video and audio files present on your device. You can transfer files from the device. You can show and search huge text... www.b4x.com Upvote 0
Maybe this tool can help you while debugging. [B4X Tool] - B4XIDEViewer V. 1.0 [B4X Tool] - B4XIDEViewer V. 1.0 What is B4XIDEViewer? -It’s a B4X Tool which can show bitmaps, images and saved pictures from your B4XIDE on your computer. You can also play video and audio files present on your device. You can transfer files from the device. You can show and search huge text... www.b4x.com