<commit_before>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * LocalDateTimeUnserializer.java                         *
 *                                                        *
 * LocalDateTime unserializer class for Java.             *
 *                                                        *
 * LastModified: Jun 26, 2015                             *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

package hprose.io.unserialize;

import hprose.io.HproseTags;
import hprose.util.DateTime;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.nio.ByteBuffer;
import java.time.LocalDateTime;

final class LocalDateTimeUnserializer implements HproseUnserializer, HproseTags {

    public final static LocalDateTimeUnserializer instance = new LocalDateTimeUnserializer();

    private static LocalDateTime toLocalDateTime(DateTime dt) {
        return LocalDateTime.of(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.nanosecond);
    }

    private static LocalDateTime toLocalDateTime(Object obj) {
        if (obj instanceof DateTime) {
            return toLocalDateTime((DateTime)obj);
        }
        return LocalDateTime.parse(obj.toString());
    }

    final static LocalDateTime read(HproseReader reader, ByteBuffer buffer) throws IOException {
        int tag = buffer.get();
        switch (tag) {
            case TagDate: return toLocalDateTime(DefaultUnserializer.readDateTime(reader, buffer));
            case TagTime: return toLocalDateTime(DefaultUnserializer.readTime(reader, buffer));
            case TagNull:
            case TagEmpty: return null;
            case TagString: return LocalDateTime.parse(StringUnserializer.readString(reader, buffer));
            case TagRef: return toLocalDateTime(reader.readRef(buffer));
            default: throw ValueReader.castError(reader.tagToString(tag), LocalDateTime.class);
        }
    }

    final static LocalDateTime read(HproseReader reader, InputStream stream) throws IOException {
        int tag = stream.read();
        switch (tag) {
            case TagDate: return toLocalDateTime(DefaultUnserializer.readDateTime(reader, stream));
            case TagTime: return toLocalDateTime(DefaultUnserializer.readTime(reader, stream));
            case TagNull:
            case TagEmpty: return null;
            case TagString: return LocalDateTime.parse(StringUnserializer.readString(reader, stream));
            case TagRef: return toLocalDateTime(reader.readRef(stream));
            default: throw ValueReader.castError(reader.tagToString(tag), LocalDateTime.class);
        }
    }
<commit_msg>Improved LocalDateTime Unserializer<commit_after>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * LocalDateTimeUnserializer.java                         *
 *                                                        *
 * LocalDateTime unserializer class for Java.             *
 *                                                        *
 * LastModified: Jun 27, 2015                             *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

package hprose.io.unserialize;

import hprose.io.HproseTags;
import hprose.util.DateTime;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.nio.ByteBuffer;
import java.time.LocalDateTime;

final class LocalDateTimeUnserializer implements HproseUnserializer, HproseTags {

    public final static LocalDateTimeUnserializer instance = new LocalDateTimeUnserializer();

    private static LocalDateTime toLocalDateTime(DateTime dt) {
        return LocalDateTime.of(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.nanosecond);
    }

    private static LocalDateTime toLocalDateTime(Object obj) {
        if (obj instanceof DateTime) {
            return toLocalDateTime((DateTime)obj);
        }
        if (obj instanceof char[]) {
            return LocalDateTime.parse(new String((char[])obj));
        }
        return LocalDateTime.parse(obj.toString());
    }

    final static LocalDateTime read(HproseReader reader, ByteBuffer buffer) throws IOException {
        int tag = buffer.get();
        switch (tag) {
            case TagDate: return toLocalDateTime(DefaultUnserializer.readDateTime(reader, buffer));
            case TagTime: return toLocalDateTime(DefaultUnserializer.readTime(reader, buffer));
            case TagNull:
            case TagEmpty: return null;
            case TagString: return LocalDateTime.parse(StringUnserializer.readString(reader, buffer));
            case TagRef: return toLocalDateTime(reader.readRef(buffer));
            default: throw ValueReader.castError(reader.tagToString(tag), LocalDateTime.class);
        }
    }

    final static LocalDateTime read(HproseReader reader, InputStream stream) throws IOException {
        int tag = stream.read();
        switch (tag) {
            case TagDate: return toLocalDateTime(DefaultUnserializer.readDateTime(reader, stream));
            case TagTime: return toLocalDateTime(DefaultUnserializer.readTime(reader, stream));
            case TagNull:
            case TagEmpty: return null;
            case TagString: return LocalDateTime.parse(StringUnserializer.readString(reader, stream));
            case TagRef: return toLocalDateTime(reader.readRef(stream));
            default: throw ValueReader.castError(reader.tagToString(tag), LocalDateTime.class);
        }
    }

{'fraction_non_alphanumeric': 0.1452563347083088, 'fraction_numerical': 0.0017678255745433118, 'mean_word_length': 1.8803563852354688, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6889461', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1447, 'n_words': 329}