I have a BufferedImage object in my hands and I want to serialize this object faster than java imageio by using JAI. However, I could not find any example. Also, I have read the documentation and I have lost in it. After serialization, I want to send the serialized object to another computer and then display this serialized object as picture in the client's monitor. Summarily, I would like only to serialize and deserialize a BufferedImage by using JAI. I can handle the other stuff.
Related
I recently read on Setting position index of filestream that it is possible to use
seek() method of BaseStream class.
But now, using .Net Framework 4.8 or greater these 2 functions seem to have been deleted.
Which stream in .Net 4.8 or greater does implement this 2 functions ?
I search a solution that is distinct from My.MyComputer.SystemFile.Seek() and is not restricted to using old VB 6 FileOpen() method !
The System.IO.FileStream class inherits the System.IO.Stream class. The latter provides the base functionality for all streams while the former provides functionality for streams backed by files. The Seek method is a member of the Stream class and thus every stream, regardless of type, has that method. That's true up to .NET 6 and will continue to be true as long as .NET exists.
The Seek method might throw a NotSupportedException in some cases, in which case the CanSeek property of that stream will be False. If you have a stream and you're not sure whether it can seek or not, test that property before calling Seek to ensure no exception will be thrown. In the case of a FileStream, the documentation (which you should already have read) tells us when to expect that property to be False:
true if the stream supports seeking; false if the stream is closed or if the FileStream was constructed from an operating-system handle such as a pipe or output to the console.
You can read the documentation of other types of streams to see whether they support seeking, e.g. MemoryStream does and NetworkStream doesn't. Basically, seeking requires random access to all the data rather than just sequential access.
There is no BaseStream property on a FileStream. The property you refer to is a member of StreamReader class. That property will return a Stream reference to the stream being read. That could be a FileStream, NetworkStream, MemoryStream or whatever. If you have a StreamReader and you want to seek to a specific position in the underlying stream but you don't know whether it is supported or not then you get the BaseStream, test the CanSeek property and, if it's True, call the Seek method.
With myStreamReader.BaseStream
If .CanSeek Then
'Advance the file pointer 64 bytes.
.Seek(64L, SeekOrigin.Current)
End If
End With
That will work no matter what type of stream backs the reader because CanSeek and Seek are members of Stream and StreamReader.BaseStream is type Stream.
Jackson's #JacksonInject annotation is useful for declaring properties of your deserialized object that are to be "injected" by the code calling for deserialization (as opposed to only being parsed from the JSON). To use this feature, it seems you have to either:
Set the InjectableValues into the ObjectMapper (which would tie them to that ObjectMapper instance and be used for all calls to it).
Get an ObjectReader [via ObjectMapper.reader(InjectableValues)] and use that ObjectReader directly to parse the JSON.
Unfortunately, neither of these is doable (from what I can see) when using Spring's RestTemplate without jumping through a lot of hoops. I don't want every object being deserialized from the RestTemplate to use injected values; nor do I see a way to customize how RestTemplate uses the underlying ObjectMapper1.
Is there a way to incorporate InjectableValues into RestTemplate's JSON deserialization?
1I suppose I could write my own custom HttpMessageConverter and figure out how to inject that into RestTemplate. But even then I don't see a way to pass the InjectableValues into ObjectMapper's read... methods. It's a lot of work even if I could.
Background: Classes that inherit from Monobehaviour can't be serialized.
Premise: A way to save the data (variables/fields and their values) of a MonoBehaviour script so it can be serialized, and deserialize it again and use this data to "fill in" a corresponding MonoBehaviour script's variable/field values.
Tried so far:
Having a serializable "wrapper/container" class that has the same fields as the MB script, but does not inherit from MB. Works nicely but every MV script needs it's own wrapper class and it's own wrapping function.
Serializing a List<FieldInfo> and fill it with the MB's fields... Works 30%;
The FieldInfos get added but are of the wrong Type, and
When deserialzing their values can't be accessed because an instance of a class is needed, but only a list is available
I feel like it can't be that hard but my Reflection skills and related are limited but seeing as saving/loading is a rather common feature I hope there is either someone who did it or someone who can point me in the right direction.
There is no easy way to serialize a MonoBehaviour using a BinaryFormatter built in .NET. There are a few options you can consider:
Using a Memento Patter. That is (more or less) what you have tried to achieve using a wrapper. Momento assumes a saving and restoring internal state of objects, so serialization is one of techniques.
Using Unity Serialization, by declaring the methods:
void Serialize(){}
void Deserialize(){}
In your MonoBehaviour script, so within the methods you will choose the properties/fields you want to serialize/deserialize.
There is an interesting framework, source code is on GitHub. It has a custom serialization framework that lets you serialize almost anything (not only monobehaviors). I have never used it, here is the forum page on Unity3d forum, I believe it's worth a look.
The answer to the question is: ScriptableObject. That's what they're for.
Put your variables in a ScriptableObject and Unity will handle the serialisation and give you a custom editor and other nice features. Recommended.
I'm making a converter from SSRS to Telerik Reporting and then using reflection to write out the source code of the .Designer.cs file.
I'm reading the CodeDom attributes with Reflection to control the output, but is there any way to invoke CodeDom to do the serialization from the given object in Memory?
How to I invoke CodeDom serialization?
Do I need to create an DesignerHost for WebForms?
Do I need to create a DesignerSerializationManager and how?
If I can serialize the Report, will it transverse the CodeDom if visibility is CONTENT or do I have to do this manually?
In short, I want to programmatically regenerate the Designer.cs from an object in memory.
http://labs.kaliko.com/2010/10/regenerate-aspxdesignercs-file.html
Thanks
Are there any compatibility issues to take care of when serailizing an object in .NET and then deserializing in Java?
I am facing problems in de-serializing an object in java which has been serialized in .NET
Here is the detailed problem statement:
In .NET platform i have a cookie.
1. Cookie is serialized
2. then it is encrypted using Triple DES algo.
3. Send it across to Java application
In Java platform
1. Decrypt the cookie using Triple DES which gives some bytes
2. Deserialize the bytes using something like
new ObjectInputStream( new ByteArrayInputStream(byte[] decryptedCookie)).readObject();
The exception stack trace I get is:
java.io.StreamCorruptedException: invalid stream header: 2F774555
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.(Unknown Source)
The WOX serializer provides interoperable serialization for .Net and Java.
If you serialize in xml then you shouldnt face any problems de-serializing in java since at worse you have to write your own bit of code to reconstruct the objects.
The way java and .Net serialise to binary differs.
How does one know the objects of the other e.g. .Net will have Dictionaries and Java Maps? (plus the bnary representation of a string might differ.
You have to use some data format that both understand and code to do the object mappings. Thus the above answers mentioning XML and WOX. I have worked with internal company produces as well.