import java.security.DEREncodable; import java.security.PEM; import java.security.PEMDecoder; import java.security.Provider; import java.security.Security; /** * JDK 26 code for the PEM preview API. It compiles on 26 and fails on 27. * Three things moved between the second and third preview (JEP 524 -> JEP 538): * 1. DEREncodable was renamed BinaryEncodable * 2. PEMDecoder.withFactory(Provider) became withFactoriesOf(Provider) * 3. PEM was a record whose content() returned a String; it is now a class whose content() returns byte[] * Driven by scripts/broken-on-27.sh, which commits the compiler's own messages. */ public class Pem26Style { public static void main(String[] args) { String text = "-----BEGIN ANKURM DEMO-----\naGVsbG8=\n-----END ANKURM DEMO-----\n"; DEREncodable decoded = PEMDecoder.of().decode(text); // 1 Provider provider = Security.getProviders()[0]; PEMDecoder viaProvider = PEMDecoder.of().withFactory(provider); // 2 if (decoded instanceof PEM pem) { String base64Text = pem.content(); // 3 System.out.println(pem.type() + " / " + base64Text); } } }