Read attribute of fixed buffer size as string.

@param attribute HDF5 attribute to read as string.
@return Fixed-length string read from HDF5 attribute
@throws UnsupportedKerasConfigurationException Unsupported Keras config
324617
private String readAttributeAsFixedLengthString(Attribute attribute, int bufferSize)
            throws UnsupportedKerasConfigurationException {
        synchronized (Hdf5Archive.LOCK_OBJECT) {
            VarLenType vl = attribute.getVarLenType();
            byte[] attrBuffer = new byte[bufferSize];
            BytePointer attrPointer = new BytePointer(attrBuffer);
            attribute.read(vl, attrPointer);
            attrPointer.get(attrBuffer);
            vl.deallocate();
            return new String(attrBuffer);
        }
    }
218628
public boolean readBoolean(boolean defaultValue, String attribute)
    {
        return Boolean.parseBoolean(getValue(String.valueOf(defaultValue), attribute));
    }
700470
public static Long getLong(final LdapEntry ctx, final String attribute) {
        return getLong(ctx, attribute, Long.MIN_VALUE);
    }
134616
public static String readStringFromFile(String path, Configuration hadoopConfig) throws IOException {
        FileSystem fileSystem = FileSystem.get(hadoopConfig);
        try (BufferedInputStream bis = new BufferedInputStream(fileSystem.open(new Path(path)))) {
            byte[] asBytes = IOUtils.toByteArray(bis);
            return new String(asBytes, "UTF-8");
        }
    }
1183618
public DeviceAttribute[] read_attribute(final DeviceProxy deviceProxy, final String[] attributeNames)
	    throws DevFailed {
	DeviceAttribute[] attr;

	build_connection(deviceProxy);

	// Read attributes on device server
	AttributeValue[] attributeValues = new AttributeValue[0];
	AttributeValue_3[] attributeValues_3 = new AttributeValue_3[0];
	AttributeValue_4[] attributeValues_4 = new AttributeValue_4[0];
	AttributeValue_5[] attributeValues_5 = new AttributeValue_5[0];
	if (deviceProxy.url.protocol == TANGO) {
	    // try 2 times for reconnection if requested
	    boolean done = false;
	    final int retries = deviceProxy.transparent_reconnection ? 2 : 1;
	    for (int i = 0; i < retries && !done; i++) {
            try {
                if (deviceProxy.device_5 != null) {
                    attributeValues_5 = deviceProxy.device_5.read_attributes_5(
                            attributeNames, deviceProxy.dev_src,
                            DevLockManager.getInstance().getClntIdent());
                }
                else if (deviceProxy.device_4 != null) {
                    attributeValues_4 = deviceProxy.device_4.read_attributes_4(
                            attributeNames, deviceProxy.dev_src,
                            DevLockManager.getInstance().getClntIdent());
                }
                else if (deviceProxy.device_3 != null) {
                    attributeValues_3 = deviceProxy.device_3.read_attributes_3(
                            attributeNames, deviceProxy.dev_src);
                }
                else if (deviceProxy.device_2 != null) {
                    attributeValues = deviceProxy.device_2.read_attributes_2(
                            attributeNames, deviceProxy.dev_src);
                }
                else {
                    attributeValues = deviceProxy.device.read_attributes(attributeNames);
                }
                done = true;
            } catch (final DevFailed e) {
                // Except.print_exception(e);
                final StringBuilder sb = new StringBuilder(attributeNames[0]);
                for (int j = 1; j < attributeNames.length; j++) {
                    sb.append(", ").append(attributeNames[j]);
                }
                Except.throw_connection_failed(e, "TangoApi_CANNOT_READ_ATTRIBUTE",
                    "Cannot read attribute(s):   " + sb.toString(),
                        deviceProxy.getFull_class_name() + ".read_attribute()");
            } catch (final Exception e) {
                manageExceptionReconnection(deviceProxy,
                        retries, i, e, this.getClass() + ".read_attribute");
            }
	    }
	    // Build a Device Attribute Object
	    // Depends on Device_impl version
	    if (deviceProxy.device_5 != null) {
            attr = new DeviceAttribute[attributeValues_5.length];
            for (int i = 0; i < attributeValues_5.length; i++) {
                attr[i] = new DeviceAttribute(attributeValues_5[i]);
            }
	    } else if (deviceProxy.device_4 != null) {
            attr = new DeviceAttribute[attributeValues_4.length];
            for (int i = 0; i < attributeValues_4.length; i++) {
                attr[i] = new DeviceAttribute(attributeValues_4[i]);
            }
	    } else if (deviceProxy.device_3 != null) {
            attr = new DeviceAttribute[attributeValues_3.length];
            for (int i = 0; i < attributeValues_3.length; i++) {
                attr[i] = new DeviceAttribute(attributeValues_3[i]);
            }
	    } else {
            attr = new DeviceAttribute[attributeValues.length];
            for (int i = 0; i < attributeValues.length; i++) {
                attr[i] = new DeviceAttribute(attributeValues[i]);
            }
	    }
	} else {
	    attr = deviceProxy.taco_device.read_attribute(attributeNames);
	}
	return attr;
    }
969132
private Integer getNonSpecialAttrLength(NamedNodeMap attributes) {
        int length = 0, maxLength = attributes.getLength();
        for (int i = 0; i < maxLength; ++i) {
            Attr a = (Attr) attributes.item(i);
            if (!isXMLNSAttribute(a)
                && !isRecognizedXMLSchemaInstanceAttribute(a)) {
                ++length;
            }
        }
        return new Integer(length);
    }
800660
private void parseAttribute(String name) throws Exception {
        String aname;
        String type;
        String value;
        int flags = LIT_ATTRIBUTE | LIT_ENTITY_REF;

        // Read the attribute name.
        aname = readNmtoken(true);
        type = getAttributeType(name, aname);

        // Parse '='
        parseEq();

        // Read the value, normalizing whitespace
        // unless it is CDATA.
        if (handler.stringInterning) {
            if ((type == "CDATA") || (type == null)) {
                value = readLiteral(flags);
            } else {
                value = readLiteral(flags | LIT_NORMALIZE);
            }
        } else {
            if ((type == null) || type.equals("CDATA")) {
                value = readLiteral(flags);
            } else {
                value = readLiteral(flags | LIT_NORMALIZE);
            }
        }

        // WFC: no duplicate attributes
        for (int i = 0; i < tagAttributePos; i++) {
            if (aname.equals(tagAttributes[i])) {
                fatal("duplicate attribute", aname, null);
            }
        }

        // Inform the handler about the
        // attribute.
        handler.attribute(aname, value, true);
        dataBufferPos = 0;

        // Note that the attribute has been
        // specified.
        if (tagAttributePos == tagAttributes.length) {
            String newAttrib[] = new String[tagAttributes.length * 2];
            System.arraycopy(tagAttributes, 0, newAttrib, 0, tagAttributePos);
            tagAttributes = newAttrib;
        }
        tagAttributes[tagAttributePos++] = aname;
    }
800723
private String getString(DerValue attribute) throws IOException {
        if (attribute == null)
            return null;
        String  value = attribute.getAsString();

        if (value == null)
            throw new IOException("not a DER string encoding, "
                    + attribute.tag);
        else
            return value;
    }
510251
def read_set_attribute(attribute_name)
      value = read_attribute(attribute_name)
      column_type = ((column_definition = self.class.columns_hash[attribute_name.to_s]) and column_definition.type)
      value = value.to_i(10) if column_type == :string
      value
    end
842141
public static String validateIndexAttribute(String attribute) {
        checkHasText(attribute, "Map index attribute must contain text");
        String keyPrefix = KEY_ATTRIBUTE_NAME.value();
        if (attribute.startsWith(keyPrefix) && attribute.length() > keyPrefix.length()) {
            if (attribute.charAt(keyPrefix.length()) != '#') {
                LOG.warning(KEY_ATTRIBUTE_NAME.value() + " used without a following '#' char in index attribute '"
                        + attribute + "'. Don't you want to index a key?");
            }
        }
        return attribute;
    }
401477
private void readClassAttributes() throws IOException, ClassfileFormatException {
        // Class attributes (including class annotations, class type variables, module info, etc.)
        final int attributesCount = inputStreamOrByteBuffer.readUnsignedShort();
        for (int i = 0; i < attributesCount; i++) {
            final int attributeNameCpIdx = inputStreamOrByteBuffer.readUnsignedShort();
            final int attributeLength = inputStreamOrByteBuffer.readInt();
            if (scanSpec.enableAnnotationInfo //
                    && (constantPoolStringEquals(attributeNameCpIdx, "RuntimeVisibleAnnotations")
                            || (!scanSpec.disableRuntimeInvisibleAnnotations && constantPoolStringEquals(
                                    attributeNameCpIdx, "RuntimeInvisibleAnnotations")))) {
                final int annotationCount = inputStreamOrByteBuffer.readUnsignedShort();
                if (annotationCount > 0) {
                    if (classAnnotations == null) {
                        classAnnotations = new AnnotationInfoList();
                    }
                    for (int m = 0; m < annotationCount; m++) {
                        classAnnotations.add(readAnnotation());
                    }
                }
            } else if (constantPoolStringEquals(attributeNameCpIdx, "InnerClasses")) {
                final int numInnerClasses = inputStreamOrByteBuffer.readUnsignedShort();
                for (int j = 0; j < numInnerClasses; j++) {
                    final int innerClassInfoCpIdx = inputStreamOrByteBuffer.readUnsignedShort();
                    final int outerClassInfoCpIdx = inputStreamOrByteBuffer.readUnsignedShort();
                    if (innerClassInfoCpIdx != 0 && outerClassInfoCpIdx != 0) {
                        if (classContainmentEntries == null) {
                            classContainmentEntries = new ArrayList<>();
                        }
                        classContainmentEntries.add(new SimpleEntry<>(getConstantPoolClassName(innerClassInfoCpIdx),
                                getConstantPoolClassName(outerClassInfoCpIdx)));
                    }
                    inputStreamOrByteBuffer.skip(2); // inner_name_idx
                    inputStreamOrByteBuffer.skip(2); // inner_class_access_flags
                }
            } else if (constantPoolStringEquals(attributeNameCpIdx, "Signature")) {
                // Get class type signature, including type variables
                typeSignature = getConstantPoolString(inputStreamOrByteBuffer.readUnsignedShort());
            } else if (constantPoolStringEquals(attributeNameCpIdx, "EnclosingMethod")) {
                final String innermostEnclosingClassName = getConstantPoolClassName(
                        inputStreamOrByteBuffer.readUnsignedShort());
                final int enclosingMethodCpIdx = inputStreamOrByteBuffer.readUnsignedShort();
                String definingMethodName;
                if (enclosingMethodCpIdx == 0) {
                    // A cpIdx of 0 (which is an invalid value) is used for anonymous inner classes declared in
                    // class initializer code, e.g. assigned to a class field.
                    definingMethodName = "<clinit>";
                } else {
                    definingMethodName = getConstantPoolString(enclosingMethodCpIdx, /* subFieldIdx = */ 0);
                    // Could also fetch method type signature using subFieldIdx = 1, if needed
                }
                // Link anonymous inner classes into the class with their containing method
                if (classContainmentEntries == null) {
                    classContainmentEntries = new ArrayList<>();
                }
                classContainmentEntries.add(new SimpleEntry<>(className, innermostEnclosingClassName));
                // Also store the fully-qualified name of the enclosing method, to mark this as an anonymous inner
                // class
                this.fullyQualifiedDefiningMethodName = innermostEnclosingClassName + "." + definingMethodName;
            } else if (constantPoolStringEquals(attributeNameCpIdx, "Module")) {
                final int moduleNameCpIdx = inputStreamOrByteBuffer.readUnsignedShort();
                classpathElement.moduleNameFromModuleDescriptor = getConstantPoolString(moduleNameCpIdx);
                // (Future work): parse the rest of the module descriptor fields, and add to ModuleInfo:
                // https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.25
                inputStreamOrByteBuffer.skip(attributeLength - 2);
            } else {
                inputStreamOrByteBuffer.skip(attributeLength);
            }
        }
    }
774063
@Override
    public DevAttrHistory_5 read_attribute_history_5(final String attributeName, final int maxSize) throws DevFailed {
        MDC.setContextMap(contextMap);
        xlogger.entry();
        checkInitialization();
        deviceMonitoring.startRequest("read_attribute_history_5");
        DevAttrHistory_5 result = null;
        try {
            final AttributeImpl attr = AttributeGetterSetter.getAttribute(attributeName, attributeList);
            if (attr.getBehavior() instanceof ForwardedAttribute) {
                final ForwardedAttribute fwdAttr = (ForwardedAttribute) attr.getBehavior();
                result = fwdAttr.getAttributeHistory(maxSize);
            } else {
                if (!attr.isPolled()) {
                    throw DevFailedUtils.newDevFailed(ExceptionMessages.ATTR_NOT_POLLED, attr.getName()
                            + " is not polled");
                }
                result = attr.getHistory().getAttrHistory5(maxSize);
            }
        } catch (final Exception e) {
            deviceMonitoring.addError();
            if (e instanceof DevFailed) {
                throw (DevFailed) e;
            } else {
                // with CORBA, the stack trace is not visible by the client if
                // not inserted in DevFailed.
                throw DevFailedUtils.newDevFailed(e);
            }
        }
        return result;

    }
782453
public static ModelNode createReadAttributeOperation(final ModelNode address, final String attributeName) {
        final ModelNode op = createOperation(READ_ATTRIBUTE_OPERATION, address);
        op.get(NAME).set(attributeName);
        return op;
    }
156251
@SuppressWarnings("unchecked")
    public <T> T attribute(String attribute) {
        return (T) servletRequest.getAttribute(attribute);
    }
1096314
public static DataBuffer readUnknown(DataInputStream s, AllocationMode allocMode, long length, DataType type) {
        // if buffer is uncompressed, it'll be valid buffer, so we'll just return it
        if (type != DataType.COMPRESSED) {
            DataBuffer buffer = Nd4j.createBuffer(type, length, false);
            buffer.read(s, allocMode, length, type);
            return buffer;
        } else {
            try {
                // if buffer is compressed one, we''ll restore it here
                String compressionAlgorithm = s.readUTF();
                long compressedLength = s.readLong();
                long originalLength = s.readLong();
                long numberOfElements = s.readLong();
                DataType originalType = DataType.values()[s.readInt()];

                byte[] temp = new byte[(int) compressedLength];
                for (int i = 0; i < compressedLength; i++) {
                    temp[i] = s.readByte();
                }

                Pointer pointer = new BytePointer(temp);
                CompressionDescriptor descriptor = new CompressionDescriptor();
                descriptor.setCompressedLength(compressedLength);
                descriptor.setCompressionAlgorithm(compressionAlgorithm);
                descriptor.setOriginalLength(originalLength);
                descriptor.setNumberOfElements(numberOfElements);
                descriptor.setOriginalDataType(originalType);
                return new CompressedDataBuffer(pointer, descriptor);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
986637
@Override
    public <A extends BasicFileAttributes> A readAttributes(final Path path, final Class<A> type,
        final LinkOption... options) throws IOException {
        if (path == null) {
            throw new IllegalArgumentException("path must be specified");
        }
        if (type == null) {
            throw new IllegalArgumentException("type must be specified");
        }
        if (!type.isAssignableFrom(ShrinkWrapFileAttributes.class)) {
            throw new UnsupportedOperationException("Only supports " + ShrinkWrapFileAttributes.class.getSimpleName()
                + " type");
        }
        if (!(path instanceof ShrinkWrapPath)) {
            throw new IllegalArgumentException("Only " + ShrinkWrapPath.class.getSimpleName() + " is supported");
        }
        final ShrinkWrapPath swPath = (ShrinkWrapPath) path;
        if (!((ShrinkWrapFileSystem) swPath.getFileSystem()).getArchive().contains(path.toString())) {
            throw new NoSuchFileException(path.toString());
        }
        final A attributes = type.cast(new ShrinkWrapFileAttributes((ShrinkWrapPath) path, getArchive(path)));
        return attributes;
    }
246949
public UnprotectedStringBuffer getAttributeValueByFullName(CharSequence name) {
		for (Attribute attr : event.attributes)
			if (attr.text.equals(name))
				return attr.value;
		return null;
	}