Source code:
@Grab(group='org.openscience.cdk', module='cdk-bundle', version='2.9')
import java.io.*;
import org.openscience.cdk.io.*;
import org.openscience.cdk.io.formats.*;
Reader stringReader = new StringReader(
"O=CN formamide\n" +
"OCC ethanol\n"
);
FormatFactory factory = new FormatFactory();
factory.registerFormat(SMILESFormatMatcher.getInstance());
IChemFormat format = factory.guessFormat(stringReader);
System.out.println("Format: " + format.getFormatName());
Output:
Format: SMILES