1 package be
.nikiroo
.fanfix
;
4 import java
.io
.IOException
;
7 import be
.nikiroo
.fanfix
.data
.MetaData
;
8 import be
.nikiroo
.fanfix
.data
.Story
;
9 import be
.nikiroo
.fanfix
.output
.BasicOutput
.OutputType
;
10 import be
.nikiroo
.utils
.Progress
;
11 import be
.nikiroo
.utils
.Version
;
12 import be
.nikiroo
.utils
.serial
.ConnectActionClient
;
14 public class RemoteLibrary
extends Library
{
20 public RemoteLibrary(String host
, int port
) throws IOException
{
24 this.localSpeed
= false;
25 this.baseDir
= Instance
.getRemoteDir(host
);
26 this.baseDir
.mkdirs();
28 this.lib
= new Library(baseDir
, OutputType
.INFO_TEXT
, OutputType
.CBZ
);
32 public synchronized Story
save(Story story
, String luid
, Progress pg
)
34 throw new java
.lang
.InternalError(
35 "No write support allowed on remote Libraries");
39 public synchronized boolean delete(String luid
) {
40 throw new java
.lang
.InternalError(
41 "No write support allowed on remote Libraries");
45 public synchronized boolean changeType(String luid
, String newType
) {
46 throw new java
.lang
.InternalError(
47 "No write support allowed on remote Libraries");
51 protected synchronized Map
<MetaData
, File
> getStories(Progress pg
) {
53 if (stories
.isEmpty()) {
55 new ConnectActionClient(host
, port
, true, null) {
56 public void action(Version serverVersion
) throws Exception
{
58 Object rep
= send("GET_METADATA *");
59 for (MetaData meta
: (MetaData
[]) rep
) {
60 stories
.put(meta
, null);
62 } catch (Exception e
) {
67 } catch (IOException e
) {
76 public synchronized File
getFile(final String luid
) {
77 File file
= lib
.getFile(luid
);
79 final File
[] tmp
= new File
[1];
81 new ConnectActionClient(host
, port
, true, null) {
82 public void action(Version serverVersion
) throws Exception
{
84 Object rep
= send("GET_STORY " + luid
);
85 Story story
= (Story
) rep
;
87 lib
.save(story
, luid
, null);
88 tmp
[0] = lib
.getFile(luid
);
90 } catch (Exception e
) {
95 } catch (IOException e
) {
103 MetaData meta
= getInfo(luid
);
104 stories
.put(meta
, file
);