// Path: xm-lep-api/src/main/java/com/icthh/xm/lep/api/LepResource.java
// public interface LepResource {
// 
//     /**
//      * Composite class constant.
//      */
//     Class<CompositeLepResource> COMPOSITE_CLASS = CompositeLepResource.class;
// 
//     LepResourceDescriptor getDescriptor();
// 
//     <V> V getValue(Class<? extends V> valueClass);
// 
//     default boolean isComposite() {
//         return COMPOSITE_CLASS.isInstance(this);
//     }
// 
//     /**
//      * Check is composite implementation and if so cast or throw exception otherwise.
//      *
//      * @return composite class representation of resource
//      */
//     default CompositeLepResource asComposite() {
//         if (isComposite()) {
//             return COMPOSITE_CLASS.cast(this);
//         } else {
//             throw new IllegalStateException("Can't cast not composite: "
//                                                 + this.getClass().getSimpleName()
//                                                 + " object to composite: "
//                                                 + COMPOSITE_CLASS.getSimpleName());
//         }
//     }
// 
// }
// 
// Path: xm-lep-api/src/main/java/com/icthh/xm/lep/api/LepResourceDescriptor.java
// public interface LepResourceDescriptor {
// 
//     /**
//      * Composite class constant.
//      */
//     Class<CompositeLepResourceDescriptor> COMPOSITE_CLASS = CompositeLepResourceDescriptor.class;
// 
//     LepResourceType getType();
// 
//     LepResourceType getSubType();
// 
//     LepResourceKey getKey();
// 
//     Instant getCreationTime();
// 
//     Instant getModificationTime();
// 
//     Version getVersion();
// 
//     default boolean isComposite() {
//         return COMPOSITE_CLASS.isInstance(this);
//     }
// 
//     /**
//      * Check is composite implementation and if so cast or throw exception otherwise.
//      *
//      * @return composite class representation of resource descriptor
//      */
//     default CompositeLepResourceDescriptor asComposite() {
//         if (isComposite()) {
//             return COMPOSITE_CLASS.cast(this);
//         } else {
//             throw new IllegalStateException("Can't cast not composite: "
//                                                 + this.getClass().getSimpleName()
//                                                 + " object to composite: "
//                                                 + COMPOSITE_CLASS.getSimpleName());
//         }
//     }
// 
// }


import com.icthh.xm.lep.api.LepResource;
import com.icthh.xm.lep.api.LepResourceDescriptor;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.stream.Collectors;
     * @param textStreamSupplier script text stream supplier
     */
    public ScriptLepResource(LepResourceDescriptor descriptor,
                             String encoding,
                             InputStreamSupplier textStreamSupplier) {
        this.descriptor = Objects.requireNonNull(descriptor, "descriptor can't be null");
        this.textStreamSupplier = Objects.requireNonNull(textStreamSupplier, "textStreamSupplier can't be null");
        setEncoding(encoding);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        StringBuilder buffer = new StringBuilder(this.getClass().getSimpleName());
        buffer.append(" [");
        buffer.append("descriptor: ").append(Objects.toString(descriptor)).append(", ");
        buffer.append("encoding: ").append(Objects.toString(encoding)).append(", ");
        buffer.append("scriptText (preview): ").append(getPreview());
        buffer.append("]");
        return buffer.toString();
    }

    private String getPreview() {
        try {
            return (textStreamSupplier == null)
                ? getPreview(scriptText)
                : getPreview(textStreamSupplier.getInputStream());
        } catch (IOException e) {
// Path: xm-lep-api/src/main/java/com/icthh/xm/lep/api/LepResource.java
// public interface LepResource {
// 
//     /**
//      * Composite class constant.
//      */
//     Class<CompositeLepResource> COMPOSITE_CLASS = CompositeLepResource.class;
// 
//     LepResourceDescriptor getDescriptor();
// 
//     <V> V getValue(Class<? extends V> valueClass);
// 
//     default boolean isComposite() {
//         return COMPOSITE_CLASS.isInstance(this);
//     }
// 
//     /**
//      * Check is composite implementation and if so cast or throw exception otherwise.
//      *
//      * @return composite class representation of resource
//      */
//     default CompositeLepResource asComposite() {
//         if (isComposite()) {
//             return COMPOSITE_CLASS.cast(this);
//         } else {
//             throw new IllegalStateException("Can't cast not composite: "
//                                                 + this.getClass().getSimpleName()
//                                                 + " object to composite: "
//                                                 + COMPOSITE_CLASS.getSimpleName());
//         }
//     }
// 
// }
// 
// Path: xm-lep-api/src/main/java/com/icthh/xm/lep/api/LepResourceDescriptor.java
// public interface LepResourceDescriptor {
// 
//     /**
//      * Composite class constant.
//      */
//     Class<CompositeLepResourceDescriptor> COMPOSITE_CLASS = CompositeLepResourceDescriptor.class;
// 
//     LepResourceType getType();
// 
//     LepResourceType getSubType();
// 
//     LepResourceKey getKey();
// 
//     Instant getCreationTime();
// 
//     Instant getModificationTime();
// 
//     Version getVersion();
// 
//     default boolean isComposite() {
//         return COMPOSITE_CLASS.isInstance(this);
//     }
// 
//     /**
//      * Check is composite implementation and if so cast or throw exception otherwise.
//      *
//      * @return composite class representation of resource descriptor
//      */
//     default CompositeLepResourceDescriptor asComposite() {
//         if (isComposite()) {
//             return COMPOSITE_CLASS.cast(this);
//         } else {
//             throw new IllegalStateException("Can't cast not composite: "
//                                                 + this.getClass().getSimpleName()
//                                                 + " object to composite: "
//                                                 + COMPOSITE_CLASS.getSimpleName());
//         }
//     }
// 
// }


// Path: xm-lep-script/src/main/java/com/icthh/xm/lep/script/ScriptLepResource.java
import com.icthh.xm.lep.api.LepResource;
import com.icthh.xm.lep.api.LepResourceDescriptor;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.stream.Collectors;

     * @param textStreamSupplier script text stream supplier
     */
    public ScriptLepResource(LepResourceDescriptor descriptor,
                             String encoding,
                             InputStreamSupplier textStreamSupplier) {
        this.descriptor = Objects.requireNonNull(descriptor, "descriptor can't be null");
        this.textStreamSupplier = Objects.requireNonNull(textStreamSupplier, "textStreamSupplier can't be null");
        setEncoding(encoding);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        StringBuilder buffer = new StringBuilder(this.getClass().getSimpleName());
        buffer.append(" [");
        buffer.append("descriptor: ").append(Objects.toString(descriptor)).append(", ");
        buffer.append("encoding: ").append(Objects.toString(encoding)).append(", ");
        buffer.append("scriptText (preview): ").append(getPreview());
        buffer.append("]");
        return buffer.toString();
    }

    private String getPreview() {
        try {
            return (textStreamSupplier == null)
                ? getPreview(scriptText)
                : getPreview(textStreamSupplier.getInputStream());
        } catch (IOException e) {
            throw new IllegalStateException("Error while getting LEP resource input stream: " + e.getMessage(), e);