psiegman / epublib

a java library for reading and writing epub files
http://www.siegmann.nl/epublib
1.06k stars 317 forks source link

Single author name with spaces problems #54

Open zemiak opened 11 years ago

zemiak commented 11 years ago

Hello,

author name like "Two Words" passed to Author as one parameter is splitted when saved in a file and then read back. When there's no space in the name, everything's all right.

Thanks for investigating!

See the test case (it fails on the first assert):

@Test
public void testSimpleNameWithStoring() throws IOException {
    final String SIMPLE_NAME = "Grossman a Simek";
    final String DATE_FORMAT = "ddMMyy-hhmmss.SSS";
    final String PATH_SEPARATOR = System.getProperty("file.separator");
    final String FILENAME_PREFIX = "/tmp/EPUB-";

    nl.siegmann.epublib.domain.Book book = new nl.siegmann.epublib.domain.Book();
    nl.siegmann.epublib.domain.Author eauthor = new nl.siegmann.epublib.domain.Author(SIMPLE_NAME);
    nl.siegmann.epublib.domain.Metadata metadata = book.getMetadata();

    List<nl.siegmann.epublib.domain.Author> authors = new ArrayList<>();
    authors.add(eauthor);
    metadata.setAuthors(authors);

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
    String fileName = FILENAME_PREFIX.replace("/", PATH_SEPARATOR) 
            + simpleDateFormat.format(new Date()) + ".txt";

    EpubWriter writer = new EpubWriter();
    FileOutputStream outputStream = new FileOutputStream(fileName);
    writer.write(book, outputStream);
    outputStream.close();

    EpubReader reader = new EpubReader();
    FileInputStream file = new FileInputStream(fileName);
    book = reader.readEpub(file);
    Metadata data = book.getMetadata();
    eauthor = data.getAuthors().get(0);

    assertEquals(SIMPLE_NAME, eauthor.getLastname());
    assertEquals("", eauthor.getFirstname());
}