@Override public void encode(final IAMCodec codec, final IAMIndex index) throws IOException, IllegalArgumentException { try { try (OutputStream stream = IO.outputStreamFrom(codec.getTargetData())) { stream.write(index.toBytes(codec.getByteOrder().toOrder())); } } catch (IOException | IllegalArgumentException cause) { throw cause; } catch (final Exception cause) { throw new IllegalArgumentException(cause); } }
@Override public IAMIndex decode(final IAMCodec codec) throws IOException, IllegalArgumentException { try { final MMFArray array = MMFArray.from(codec.getSourceData()); final ByteOrder order = IAMIndexLoader.HEADER.orderOf(array); codec.useByteOrder(IAMByteOrder.from(order)); return new IAMIndexLoader(array.withOrder(order)); } catch (IOException | IllegalArgumentException cause) { throw cause; } catch (final Exception cause) { throw new IllegalArgumentException(cause); } }
@Override public String format(final int[] array) throws NullPointerException, IllegalArgumentException { return new String(IAMCodec._formatBytes_(array), this.charset); }
@Override public int[] parse(final String string) throws NullPointerException, IllegalArgumentException { return IAMCodec._parseBytes_(string.getBytes(this.charset)); }
@Override public int[] parse(final String string) throws NullPointerException, IllegalArgumentException { return IAMCodec._parseChars_(string.toCharArray()); }