No, there isn't. The instanceof "spaghetti" would have to exist somewhere anyway. Make a generic method that does that:

public <T> void write(DataOutputStream stream, T object) {
   // instanceofs and writes here
}
Answer from Bozho on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › DataOutput.html
DataOutput (Java Platform SE 8 )
October 20, 2025 - The DataOutput interface provides for converting data from any of the Java primitive types to a series of bytes and writing these bytes to a binary stream.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › io › DataOutput.html
DataOutput (Java SE 17 & JDK 17)
January 20, 2026 - The DataOutput interface provides for converting data from any of the Java primitive types to a series of bytes and writing these bytes to a binary stream.
🌐
GeeksforGeeks
geeksforgeeks.org › java › dataoutputstream-in-java
Java.io.DataOutputStream in Java - GeeksforGeeks
September 11, 2023 - A data output stream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in.
🌐
MIT
web.mit.edu › java_v1.0.2 › www › javadoc › java.io.DataOutput.html
Interface java.io.DataOutput
extends Object DataOutput is an interface describing streams that can write output in a machine-independent format.
🌐
TechVidvan
techvidvan.com › tutorials › java-dataoutputstream-class
Java DataOutputStream Class - TechVidvan
January 13, 2025 - The Java DataOutputStream class enables machine-independent writing of primitive Java data types to the output stream by applications.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › DataOutputStream.html
DataOutputStream (Java Platform SE 8 )
3 days ago - A data output stream lets an application write primitive Java data types to an output stream in a portable way.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.io.dataoutputstream
DataOutputStream Class (Java.IO) | Microsoft Learn
A data output stream lets an application write primitive Java data types to an output stream in a portable way.
🌐
Bureau of Economic Geology
beg.utexas.edu › lmod › agi.servlet › doc › detail › java › io › class-use › DataOutput.html
: Uses of Interface java.io.DataOutput
Uses of DataOutput in java.io · Subinterfaces of DataOutput in java.io interface ObjectOutput ObjectOutput extends the DataOutput interface to include writing of objects
🌐
Novell
novell.com › documentation › extendas35 › docs › help › java › jdk › api › java › io › class-use › DataOutput.html
Java(TM) 2 Platform, Standard Edition, v1.2.2 API Specification: Uses of Interface java.io.DataOutput
Uses of DataOutput in java.io · Subinterfaces of DataOutput in java.io interface ObjectOutput ObjectOutput extends the DataOutput interface to include writing of objects
🌐
Apache Lucene
lucene.apache.org › core › 5_3_0 › core › org › apache › lucene › store › DataOutput.html
DataOutput (Lucene 5.3.0 API)
java.lang.Object · org.apache... PagedBytes.PagedBytesDataOutput · public abstract class DataOutput extends Object · Abstract base class for performing write operations of Lucene's low-level data types....
🌐
Kony
docs.kony.com › 8_x_PDFs › jsandroidzip › index.html
java.io.DataOutputStream - Documentation - JSDuck
java.io.DataOutput · java.io.DataOutputStream · java.io.EOFException · java.io.Externalizable · java.io.File · java.io.FileDescriptor · java.io.FileFilter · java.io.FileInputStream · java.io.FileNotFoundException · java.io.FileOutputStream · java.io.FilePermission ·
🌐
Javadoc.io
javadoc.io › doc › org.apache.nifi › nifi-utils › 1.1.0 › org › apache › nifi › stream › io › DataOutputStream.html
DataOutputStream - nifi-utils 1.1.0 javadoc
https://javadoc.io/doc/org.apache.nifi/nifi-utils · Current version 1.1.0 · https://javadoc.io/doc/org.apache.nifi/nifi-utils/1.1.0 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org.apache.nifi/nifi-utils/1.1.0/package-list ·
🌐
Coderanch
coderanch.com › t › 439387 › java › writing-zip-file-DataOutputStream
writing .zip file into DataOutputStream (I/O and Streams forum at Coderanch)
A data output stream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in. DataOutputStream The cool thing about Java IO is that copying to a socket is the same as copying to a file ...
🌐
Java Almanac
javaalmanac.io › jdk › 1.1 › api › java.io.DataOutput.html
Interface java.io.DataOutput
public interface DataOutput The data output interface is implemented by streams that can write primitive Java data types to an output stream in a machine-independent manner.
🌐
GitHub
github.com › AdoptOpenJDK › openjdk-jdk11 › blob › master › src › java.base › share › classes › java › io › DataOutputStream.java
openjdk-jdk11/src/java.base/share/classes/java/io/DataOutputStream.java at master · AdoptOpenJDK/openjdk-jdk11
March 2, 2019 - * @see java.io.DataInputStream · * @since 1.0 · */ public · class DataOutputStream extends FilterOutputStream implements DataOutput { /** * The number of bytes written to the data output stream so far. * If this counter overflows, it will be wrapped to Integer.MAX_VALUE.
Author   AdoptOpenJDK
🌐
Berkeley
titanium.cs.berkeley.edu › doc › java-api-1.0 › java › io › DataOutputStream.html
DataOutputStream
This class lets you write primitive Java data types to a stream in a portable way. Primitive data types are well understood types with associated operations. For example, an Integer is considered to be a good primitive data type. The data can be converted back using a DataInputStream.
🌐
Bukkit
bukkit.org › threads › dataoutputstream-writing-issue.167989
Solved - DataOutputStream writing issue | Bukkit Forums
August 15, 2013 - This isn't directly related to the Bukkit API but I thought I would post this here anyway. I was following this [media] tutorial and early in the...